0

我正在使用 scipy.cluster 进行层次聚类,然后在不同的截止值下使用 fcluster。我也想使用 scikit 的剪影分数。我看到帖子如何使用 scikit-learn 剪影分数计算 scipy 的 fcluster 的剪影分数? 但是,我收到错误“布尔索引太多”??

我的代码如下:

import fastcluster
from sklearn import metrics
from scipy.cluster import hierarchy as hac


Temps=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
Distance=[]
#read the Distance obtained as a list then
Distances=np.array(Distances)
Z=fastcluster.linkage(Distances, "complete", "euclidean")
for Cutoff in Temps:
    results=hac.fcluster(Z,Cutoff,'distance')
    metrics.silhouette_score(Distances, results, metric="euclidean")

错误报告是:

Traceback (most recent call last):
  File "Clustering_2.py", line 93, in <module>
    main(argv)
  File "Clustering_2.py", line 69, in main
    silscore=metrics.silhouette_score(Distances, results,metric='euclidean')
  File "/home/wangz18/site-packages2/sklearn/metrics/cluster/unsupervised.py", line 93, in silhouette_score
    return np.mean(silhouette_samples(X, labels, metric=metric, **kwds))
  File "/home/wangz18/site-packages2/sklearn/metrics/cluster/unsupervised.py", line 157, in silhouette_samples
    for i in range(n)])
  File "/home/wangz18/site-packages2/sklearn/metrics/cluster/unsupervised.py", line 187, in _intra_cluster_distance
    a = np.mean(distances_row[mask])
ValueError: too many boolean indices

有什么问题?请指教。谢谢

4

1 回答 1

0

我有同样的问题,请检查:

  1. 距离为N*N,N为样本数

  2. 结果为N,值为簇的类别

  3. 簇数应> 1

如果#1 和#2 是正确的,那么它们应该是正确的。

于 2019-03-14T16:15:57.567 回答