fixes variale name error
This commit is contained in:
parent
c48ae50ade
commit
2cd6cdd4a6
@ -33,27 +33,37 @@ class Kmeans(object):
|
|||||||
labels = km.fit_predict(zip(xs, ys))
|
labels = km.fit_predict(zip(xs, ys))
|
||||||
return zip(ids, labels)
|
return zip(ids, labels)
|
||||||
|
|
||||||
def spatial_balanced(self, query, no_clusters, no_init=20, target_per_cluster = None, value_column = None):
|
def spatial_balanced(self, query, no_clusters, no_init=20,
|
||||||
params = { "subquery": query,
|
target_per_cluster=None, value_column=None):
|
||||||
"geom_col": "the_geom",
|
params = {
|
||||||
"id_col": "cartodb_id",
|
"subquery": query,
|
||||||
"value_column" : value_column }
|
"geom_col": "the_geom",
|
||||||
|
"id_col": "cartodb_id",
|
||||||
|
"value_column": value_column,
|
||||||
|
}
|
||||||
|
|
||||||
data = self.data_provider.get_spatial_balanced_kmeans(params)
|
data = self.data_provider.get_spatial_balanced_kmeans(params)
|
||||||
|
|
||||||
xs = data[0]['xs']
|
lons = data[0]['xs']
|
||||||
ts = data[0]['ys']
|
lats = data[0]['ys']
|
||||||
ids = data[0]['ids']
|
ids = data[0]['ids']
|
||||||
values = data[0]['values']
|
values = data[0]['values']
|
||||||
|
|
||||||
total_value = np.sum(values)
|
total_value = np.sum(values)
|
||||||
|
|
||||||
if target_per_cluster is None:
|
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)
|
bal_kmeans = BalancedGroupsKMeans(
|
||||||
labels = km.fit_predict(zip(xs,ys), values=values)
|
n_clusters=17,
|
||||||
return zip(ids,labels)
|
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,
|
def nonspatial(self, subquery, colnames, no_clusters=5,
|
||||||
standardize=True, id_col='cartodb_id'):
|
standardize=True, id_col='cartodb_id'):
|
||||||
|
Loading…
Reference in New Issue
Block a user