I'm trying to draw a complete-link scipy.cluster.hierarchy.dendrogram
, and I found that scipy.cluster.hierarchy.linkage
is slower than sklearn.AgglomerativeClustering
.
However, sklearn.AgglomerativeClustering
doesn't return the distance between clusters and the number of original observations, which scipy.cluster.hierarchy.dendrogram
needs. Is there a way to take them?
I made a scipt to do it without modifying sklearn and without recursive functions. Before using note that:
Import the packages:
Function to compute weights and distances:
Make sample data of 2 clusters with 2 subclusters:
Sample data:
Fit the clustering model
Call the function to find the distances, and pass it to the dendogram
Ouput dendogram: