How to compute cluster assignments from linkage/distance matrices in scipy in Python? How to compute cluster assignments from linkage/distance matrices in scipy in Python? numpy numpy

How to compute cluster assignments from linkage/distance matrices in scipy in Python?


If I understand you right, that is what fcluster does:

scipy.cluster.hierarchy.fcluster(Z, t, criterion='inconsistent', depth=2, R=None, monocrit=None)

Forms flat clusters from the hierarchical clustering defined by the linkage matrix Z.

...

Returns: An array of length n. T[i] is the flat cluster number to which original observation i belongs.

So just call fcluster(linkage_matrix, t), where t is your threshold.


If you'd like to see the members at every cluster level and in what order they are agglomerated see https://stackoverflow.com/a/43170608/5728789