如何使用scikit-learn轮廓分数计算scipy集群的轮廓分数? [英] How to calculate Silhouette Score of the scipy's fcluster using scikit-learn silhouette score?

查看:169
本文介绍了如何使用scikit-learn轮廓分数计算scipy集群的轮廓分数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆