为什么会收到群集警告?

时间:2019-10-20 19:29:01

标签: python scipy hierarchical-clustering

我正在尝试在距离矩阵上执行分层的聚集聚类。为此,我制作了一个邻居图,然后将其提供给sklearn的AgglomerativeClustering算法。当我这样做时,它可以工作,但是出现以下错误:

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()

0 个答案:

没有答案