2021年2月5日星期五

Python. From dendrogram to MST representation

Im trying to plot a minimum spanning tree graph from a formed dendrogram of correlation matrix. Any ideas on how to do this?

The "toy" correlation matrix:

import scipy.cluster.hierarchy as sch, numpy as np, pandas as pd, matplotlib.pyplot as plt    cor = np.array([      [ 1.00,  0.70,  0.20],      [ 0.70,  1.00, -0.20],      [ 0.20, -0.20,  1.00],  ])  cor = pd.DataFrame(cor)  

has following linkage matrix and distance metrix in order to get a dendrogram:

dist = ((1-cor)/2.)**.5  link = sch.linkage(dist, method = 'single')  plt.figure(1)  sch.dendrogram(link)  plt.show()  

My goal is to plot a minimum spanning tree graph given information in distance metrix "link". Something like this immage:

enter image description here

Thank you for any help you can provide.

https://stackoverflow.com/questions/66031592/python-from-dendrogram-to-mst-representation February 04, 2021 at 12:24AM

没有评论:

发表评论