在Scipy层次聚类中对树状图进行修剪 [英] Pruning dendrogram at levels in Scipy Hierarchical Clustering
本文介绍了在Scipy层次聚类中对树状图进行修剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有很多数据点,这些数据点使用Scipy
层次聚类以以下方式聚类.假设我要修剪"1500"级别的树状图?怎么做? (我尝试使用'p'参数,但这不是我期望的值)
I have lot of data points which are clustered in the following way using Scipy
Hierarchical Clustering. Let's say I want to prune the dendogram at level '1500'? How to do that? (I've tried using 'p' parameter and that is not what I'm expecting)
Z = dendrogram(linkage_matrix,
truncate_mode='lastp',
color_threshold=1,
labels=df.session.tolist(),
distance_sort='ascending')
plt.title("Hierachical Clustering")
plt.show()
推荐答案
As specified in the scipy documentation, if a cluster node is under color_threshold
, then all of its descendants will be the same color (not blue). The links connecting nodes above color_threshold
will be blue.
在您的示例中,为color_threshold=1
.由于所有节点都在1
之上,因此所有链接均为蓝色.
In your example, color_threshold=1
. Since all the nodes are above 1
, all of the links are blue.
尝试
Z = dendrogram(linkage_matrix,
color_threshold=1500,
distance_sort='ascending')
这篇关于在Scipy层次聚类中对树状图进行修剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文