hierarchical clustering on correlations in Python scipy/numpy?

后端 未结 1 442
自闭症患者
自闭症患者 2021-02-03 10:39

How can I run hierarchical clustering on a correlation matrix in scipy/numpy? I have a matrix of 100 rows by 9 columns, and I\'d like to hierarchicall

1条回答
  •  旧时难觅i
    2021-02-03 11:37

    Just change the metric to correlation so that the first line becomes:

    Y=pdist(X, 'correlation')
    

    However, I believe that the code can be simplified to just:

    Z=linkage(X, 'single', 'correlation')
    dendrogram(Z, color_threshold=0)
    

    because linkage will take care of the pdist for you.

    0 讨论(0)
提交回复
热议问题