gpt4 book ai didi

python - seaborn clustermap FloatingPointError : NaN dissimilarity value

转载 作者:行者123 更新时间:2023-12-04 09:01:23 33 4
gpt4 key购买 nike

我尝试运行此代码:

import pandas as pd
import seaborn as sns

df = pd.DataFrame(clusters, columns=cols)

sns.clustermap(df, cmap="vlag", vmin=0, vmax=1, metric="correlation",
z_score=None, standard_scale=None, yticklabels=True,
figsize=(size, size))
集群的值(value)是:
clusters = [[0.89463602, 0.,         0.,         0.85185185, 0.9023569,  0.,
0., 0.83333333, 0., 0., 0., ],

[0.75, 0.66666667, 0., 0., 0.69444444, 0.,
0.89272031, 0., 0.69444444, 0., 0.69444444,],

[0.85185185, 0.88910175, 0., 0., 0.9043771, 0.,
0., 0., 0.89092141, 0.77777778, 0.69444444,],

[0.75, 0.89825458, 0., 0., 0.77777778, 0.,
0.8908046, 0., 0.75, 0.91550069, 0.8, ],]
我收到以下错误:
in linkage
linkage_wrap(N, X, Z, mthidx[method])
FloatingPointError: NaN dissimilarity value.
什么原因导致它的任何想法?

最佳答案

您的两列全为零,并且根本没有变化,使其返回具有相关性的 nan :

cols = ["col"+str(i) for i in range(11)]
df = pd.DataFrame(clusters, columns=cols)
df.corr()

col0 col1 col2 col3 col4 col5 col6 col7 col8 col9 col10
col0 1.000000 -0.652805 NaN 0.755353 0.914034 NaN -0.971167 0.755353 -0.607892 -0.232318 -0.792705
col1 -0.652805 1.000000 NaN -0.967396 -0.353987 NaN 0.461102 -0.967396 0.982783 0.761192 0.976659
col2 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
col3 0.755353 -0.967396 NaN 1.000000 0.537949 NaN -0.577350 1.000000 -0.978166 -0.573568 -0.990826
col4 0.914034 -0.353987 NaN 0.537949 1.000000 NaN -0.943651 0.537949 -0.352431 0.181392 -0.546475
col5 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
col6 -0.971167 0.461102 NaN -0.577350 -0.943651 NaN 1.000000 -0.577350 0.401476 0.079648 0.627048
col7 0.755353 -0.967396 NaN 1.000000 0.537949 NaN -0.577350 1.000000 -0.978166 -0.573568 -0.990826
col8 -0.607892 0.982783 NaN -0.978166 -0.352431 NaN 0.401476 -0.978166 1.000000 0.665620 0.962359
col9 -0.232318 0.761192 NaN -0.573568 0.181392 NaN 0.079648 -0.573568 0.665620 1.000000 0.636492
col10 -0.792705 0.976659 NaN -0.990826 -0.546475 NaN 0.627048 -0.990826 0.962359 0.636492 1.000000

df[['col2','col5']]

col2 col5
0 0.0 0.0
1 0.0 0.0
2 0.0 0.0
3 0.0 0.0
您可以删除这些列并绘图,或者您必须使用欧几里得或堪培拉作为度量。

关于python - seaborn clustermap FloatingPointError : NaN dissimilarity value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63550024/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com