Pruning dendrogram at levels in Scipy Hierarchical Clustering

家住魔仙堡 提交于 2019-12-07 18:27:59

问题


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()


回答1:


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.

In your example, color_threshold=1. Since all the nodes are above 1, all of the links are blue.

Try instead

Z = dendrogram(linkage_matrix,
       color_threshold=1500,
       distance_sort='ascending')


来源:https://stackoverflow.com/questions/26608412/pruning-dendrogram-at-levels-in-scipy-hierarchical-clustering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!