Trimming dendrograms at levels in Scipy Hierarchical Clustering

I have many data points that are clustered as follows using Scipy Hierarchical Clustering. Say I want to trim the dendrogram at the 1500 level? How to do it? (I tried using the "p" parameter, and that is not what I expect)

 Z = dendrogram(linkage_matrix, truncate_mode='lastp', color_threshold=1, labels=df.session.tolist(), distance_sort='ascending') plt.title("Hierachical Clustering") plt.show() 

Results

+2
python scipy hierarchical-clustering
source share
1 answer

As indicated in the meager documentation , if the node cluster is under color_threshold , then all its descendants will be the same color (not blue). Connections connecting nodes above color_threshold will be blue.

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

Try instead

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

All Articles