我试图在距离矩阵上执行层次聚集聚类。为此,我制作了一个kneighbors图,然后将其输入sklearn的聚集聚类算法。当我这样做的时候,它工作了,但是我得到了以下错误:
Warning (from warnings module):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/cluster/hierarchical.py", line 463
out = hierarchy.linkage(X, method=linkage, metric=affinity)
ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
我试过在其他地方寻找,但我似乎不明白为什么会抛出这个错误,如果它的工作和显示的数据。为什么会这样?(以下代码仅供参考)
plt.figure(figsize=(10, 6))
for index, linkage in enumerate(('average',
'complete',
'ward',
'single')):
plt.subplot(1, 4, index + 1)
model = AgglomerativeClustering(linkage=linkage,
connectivity=connectivity,
n_clusters=n_clusters)
t0 = time.time()
model.fit(X)
elapsed_time = time.time() - t0
plt.scatter(X[:, 0], X[:, 1], c=model.labels_,
cmap=plt.cm.nipy_spectral)
plt.title('linkage=%s\n(time %.2fs)' % (linkage, elapsed_time),
fontdict=dict(verticalalignment='top'))
plt.axis('equal')
plt.axis('off')
plt.subplots_adjust(bottom=0, top=.89, wspace=0,
left=0, right=1)
plt.suptitle('n_cluster=%i, connectivity=%r' %
(n_clusters, connectivity is not None), size=17)
plt.show()
目前没有回答
相关问题 更多 >
编程相关推荐