Label Ordering In Scipy Dendrogram
In python, I have an N by N distance matrix dmat, where dmat[i,j] encodes the distance from entity i to entity j. I'd like to view a dendrogram. I did: from scipy.cluster.hierarchy
Solution 1:
The first argument to linkage
must be either the distances in condensed format, or the array of points being clustered. If you pass the square (N x N) distance matrix, linkage
interprets it as N points in N-dimensional space.
You can convert from your square matrix to the condensed form with scipy.spatial.distance.squareform
.
Add this to the beginning of your file
from scipy.spatial.distanceimport squareform
and replace this
Z=linkage(dmat)
with
Z = linkage(squareform(dmat))
Post a Comment for "Label Ordering In Scipy Dendrogram"