small syntax fixes
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user