2个树状图和凝聚态相关矩阵的热图 [英] 2 Dendrograms + Heatmap from condensed correlationmatrix with scipy
问题描述
我尝试创建如下所示的内容:对ontop层次聚类的结果进行分析数据在python中的矩阵
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 ...
推荐答案
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.
您必须修改代码,以不将平方距离矩阵传递给 linkage
.如果您已经有了这样的矩阵,则可以使用
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
.
为避免进一步的混乱,我更新了链接答案中的代码,以使它将压缩的距离矩阵传递给 linkage
.
To avoid further confusion, I updated the code in the linked answer so that it passes a condensed distance matrix to linkage
.
这篇关于2个树状图和凝聚态相关矩阵的热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!