【发布时间】:2023-03-12 20:53:02
【问题描述】:
我有四个用户之间的相似度矩阵。我想做一个凝聚聚类。代码是这样的:
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]。如果错了,你能告诉我如何做基于相似度的凝聚算法吗?如果是对的,相似度矩阵很大,我如何从一个巨大的列表中选择最优的聚类结果?谢谢
【问题讨论】:
标签: python scikit-learn hierarchical-clustering