Update getting settings params in clustering
"Different ways to cluster plants"
import numpy as np
+import pandas as pd
from sklearn import cluster, preprocessing
@@ -23,14 +24,17 @@ def build_cluster_method_dict(settings):
return cluster_method_dict
-def cluster_kmeans(grouped, region, tech, settings):
+def cluster_kmeans(
+ grouped: pd.DataFrame, region: str, tech: str, settings: dict
+) -> pd.DataFrame:
- if region in settings["alt_num_clusters"]:
- if tech in settings["alt_num_clusters"][region]:
- n_clusters = settings["alt_num_clusters"][region][tech]
+ if region in settings.get("alt_num_clusters", {}):
+ # if tech in settings["alt_num_clusters"][region]:
+ n_clusters = settings["alt_num_clusters"][region].get(tech)
else:
- n_clusters = settings["num_clusters"][tech]
+ n_clusters = settings["num_clusters"].get(tech)
+ if n_clusters:
clusters = cluster.KMeans(n_clusters=n_clusters, random_state=6).fit(
preprocessing.StandardScaler().fit_transform(grouped)
)
