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.
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