5
我有一个四个用户之间的相似矩阵。我想做一个凝聚聚类。代码是这样的:sklearn凝聚聚类输入数据
lena = np.matrix('1 1 0 0;1 1 0 0;0 0 1 0.2;0 0 0.2 1')
X = np.reshape(lena, (-1, 1))
print("Compute structured hierarchical clustering...")
st = time.time()
n_clusters = 3 # number of regionsle
ward = AgglomerativeClustering(n_clusters=n_clusters,
linkage='complete').fit(X)
print ward
label = np.reshape(ward.labels_, lena.shape)
print("Elapsed time: ", time.time() - st)
print("Number of pixels: ", label.size)
print("Number of clusters: ", np.unique(label).size)
print label
标签的打印结果是这样的:
[[1 1 0 0]
[1 1 0 0]
[0 0 1 2]
[0 0 2 1]]
这是否意味着它给人的可能集群结果列表中,我们可以选择一个从他们身上?喜欢选择:[0,0,2,1]。如果是错误的,你能告诉我怎么做基于相似性的凝聚算法吗?如果它是正确的,相似矩阵是巨大的,我怎么能从一个巨大的列表中选择最优的聚类结果?由于
但是,如果他需要一个层次聚类呢? – Itay