Interactive dengoram with plotly and custom distance, linkage functions

0

I have a matrix X and usually I use scipy to make a dendogram and plot it:

from scipy.cluster.hierarchy import dendrogram, linkage
from scipy.spatial.distance import squareform
distances = np.sqrt((1 - X).round(5) / 2)
clusters = linkage(squareform(distances.values), method='ward')
dendogram(clusters)

However, in my case X is 900x900 matrix, so matplotlib can’t plot all the features on a single plot in an interpretable way. I tried to use plotly dendogram function:

fig = ff.create_dendrogram(X, linkagefun=lambda x: linkage(x, 'ward'), distfun=lambda x: np.sqrt((1 - x).round(5) / 2))

However, plots and distances are different from scipy.dendogram function output. How can I configure plotly to get the same result?

Thanks

HI @oleksandrproskurin,
To understand how ff.create_dendogram () works
you can inspect the code here:

https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/plotly/figure_factory/_dendrogram.py.