fixes variale name error

This commit is contained in:
Andy Eschbacher 2018-02-16 13:31:17 -05:00
parent c48ae50ade
commit 2cd6cdd4a6

View File

@ -33,27 +33,37 @@ class Kmeans(object):
labels = km.fit_predict(zip(xs, ys))
return zip(ids, labels)
def spatial_balanced(self, query, no_clusters, no_init=20, target_per_cluster = None, value_column = None):
params = { "subquery": query,
"geom_col": "the_geom",
"id_col": "cartodb_id",
"value_column" : value_column }
def spatial_balanced(self, query, no_clusters, no_init=20,
target_per_cluster=None, value_column=None):
params = {
"subquery": query,
"geom_col": "the_geom",
"id_col": "cartodb_id",
"value_column": value_column,
}
data = self.data_provider.get_spatial_balanced_kmeans(params)
xs = data[0]['xs']
ts = data[0]['ys']
lons = data[0]['xs']
lats = data[0]['ys']
ids = data[0]['ids']
values = data[0]['values']
total_value = np.sum(values)
total_value = np.sum(values)
if target_per_cluster is None:
target_per_cluster = total_value / float(no_clusters)
target_per_cluster = total_value / float(no_clusters)
km = BalancedGroupsKMeans(n_clusters=17,max_iter=100, max_cluster_size=target_per_cluster)
labels = km.fit_predict(zip(xs,ys), values=values)
return zip(ids,labels)
bal_kmeans = BalancedGroupsKMeans(
n_clusters=17,
max_iter=100,
max_cluster_size=target_per_cluster
)
labels = bal_kmeans.fit_predict(
zip(lons, lats),
values=values
)
return zip(ids, labels)
def nonspatial(self, subquery, colnames, no_clusters=5,
standardize=True, id_col='cartodb_id'):