scipy linkage:Distance matrix ‘X’ must be symmetric

Published on:
Last updated:

This post is also available in: 日本語 (Japanese)

This is a note about how to solve "Distance matrix 'X' must be symmetric" when create dendrogram by using scipy.cluster.hierarchy.linkage .

Distance matrix 'X' must be symmetric

At first, checked the .shape of matrix 'X' so that matrix 'X' is symmetric.

Then, because it is a distance matrix, it should be finite number.
In my case, the error occured because it contains infs.

All elements of the condensed distance matrix must be finite, i.e. no NaNs or infs.
https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html

About
Kuniyoshi Takemoto is the founder of Amelt.net LLC, and editor of this blog(www.amelt.net).Learn more and follow me on LinkedIn.