如何使用scikit-learn轮廓分数计算scipy集群的轮廓分数? [英] How to calculate Silhouette Score of the scipy's fcluster using scikit-learn silhouette score?
问题描述
我正在使用scipy.cluster.hierarchy.linkage作为聚类算法,并将结果链接矩阵传递给
I am using scipy.cluster.hierarchy.linkage as a clustering algorithm and pass the result linkage matrix to scipy.cluster.hierarchy.fcluster, to get the flattened clusters, for various thresholds.
我想计算结果的Silhouette分数,并比较它们以选择最佳阈值,而不希望自己实现,而不要使用scikit-learn的
I would like to calculate the Silhouette score of the results and compare them to choose the best threshold and prefer not to implement it on my own but use scikit-learn's sklearn.metrics.silhouette_score. How can I rearrange my clustering results as an input to sklearn.metrics.silhouette_score?
推荐答案
您不必这样做.
fcluster的结果可以直接输入到silhouette_score中.
Results of fcluster can directly be fed into silhouette_score.
distmatrix1 = scipy.spatial.distance.squareform(distmatrix + distmatrix.T)
ddgm = scipy.cluster.hierarchy.linkage(distmatrix1, method="average")
nodes = scipy.cluster.hierarchy.fcluster(ddgm, 4, criterion="maxclust")
metrics.silhouette_score(distmatrix + distmatrix.T , nodes, metric='euclidean')
这篇关于如何使用scikit-learn轮廓分数计算scipy集群的轮廓分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!