small syntax fixes

This commit is contained in:
Andy Eschbacher
2018-02-09 16:22:10 -05:00
parent d2574c20ef
commit c48ae50ade
2 changed files with 13 additions and 7 deletions

View File

@@ -24,12 +24,18 @@ $$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
-- deviation of 1
-- id_colname: name of the id column
CREATE OR REPLACE FUNCTION CDB_KMeansBalanced(query text, no_clusters integer, value_col TEXT default NULL, no_init integer default 20, max_per_cluster float default NULL )
RETURNS table (cartodb_id integer, cluster_no integer) as $$
CREATE OR REPLACE FUNCTION CDB_KMeansBalanced(
query text,
no_clusters integer,
value_col TEXT default NULL,
no_init integer default 20,
max_per_cluster float default NULL)
RETURNS table(cartodb_id integer, cluster_no integer)
AS $$
from crakshaft.clustering import KmeansBallanced
kmeans = KmeansBallanced()
return kmeans.spatial_balanced(query,no_clusters,no_init, max_per_cluster, value_col)
from crankshaft.clustering import KmeansBalanced
kmeans = KmeansBalanced()
return kmeans.spatial_balanced(query,no_clusters,no_init, max_per_cluster, value_col)
$$ LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;

View File

@@ -1,5 +1,5 @@
from sklearn.cluster import KMeans
from balanced_kmeans import BalancedGroupsKMeans
from .balanced_kmeans import BalancedGroupsKMeans
import numpy as np
@@ -51,7 +51,7 @@ class Kmeans(object):
if target_per_cluster is None:
target_per_cluster = total_value / float(no_clusters)
km = KmeansBallanced(n_clusters=17,max_iter=100, max_cluster_size=target_per_cluster)
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)