我使用scipy.cluster和fcluster在不同的截断条件下进行层次聚类。我还想使用scikit的剪影核心。我看到帖子如何计算scipy的剪影得分';s fcluster使用scikit学习轮廓分数?然而,我得到了错误"太多的布尔指数"??
我的代码如下:
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
怎么了?请告知。感谢
我有同样的问题,请检查:
-
距离为N*N,N为样本数
-
结果为N,该值为集群的类别
-
集群数量应>1
如果#1和#2是正确的,那么它们应该是正确的。