2 Dendrograms + Heatmap from condensed correlationmatrix with scipy

烈酒焚心 提交于 2021-01-29 05:23:03

问题


I try to create something like this: plotting results of hierarchical clustering ontop of a matrix of data in python

Unfortunatelly when I try to execute the code, I get the following warnings:

Warning (from warnings module):
  File "C:\Users\USER1\Desktop\test.py", line 15
    Y = sch.linkage(D, method='centroid')
ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix

Warning (from warnings module):
  File "C:\Users\USER1\Desktop\test.py", line 22
    Y = sch.linkage(D, method='single')
ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix

In addition, a small window opens but crashes ...


回答1:


That code that you linked to has a problem: it passes the square distance matrix to linkage. The first argument of linkage has been a frequent source of confusion, so in recent versions of scipy, the code generates a warning if something that looks like a square distance matrix is passed in.

You'll have to modify your code to not pass a square distance matrix to linkage. If you already have a such a matrix, you can convert it to the condensed form expected by linkage with the function scipy.spatial.distance.squareform.

To avoid further confusion, I updated the code in the linked answer so that it passes a condensed distance matrix to linkage.



来源:https://stackoverflow.com/questions/52517438/2-dendrograms-heatmap-from-condensed-correlationmatrix-with-scipy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!