def computeKmeans(self,Number_of_clusters,data, iterations = 100):
partition = dict()
nb_clusters = Number_of_clusters # this is the number of cluster the dataset is supposed to be partitioned into
distances = nx.to_numpy_matrix(data)
clusterid, error, nfound = KMeans(distances, nclusters= nb_clusters, npass=300)
uniq_ids = list(set(clusterid))
new_ids = [ uniq_ids.index(val) for val in clusterid]
for i,value in enumerate(new_ids):
partition[i] = value
return partition
评论列表
文章目录