gpt4 book ai didi

python - Seaborn kdeplot 没有绘制一些数据?

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:53 25 4
gpt4 key购买 nike

我正在尝试获取 Seaborn kdeplot处理我的数据集的示例。由于某种原因,我的一个数据集根本没有绘制,但另一个似乎绘制得很好。为了获得最小的工作示例,我仅从非常大的数据集中采样了 10 行。

我的输入数据如下所示:

#Dataframe dfA
index x y category
0 595700 5 1.000000 14.0
1 293559 4 1.000000 14.0
2 562295 3 0.000000 14.0
3 219426 4 1.000000 14.0
4 592731 2 1.000000 14.0
5 178573 3 1.000000 14.0
6 553156 4 0.500000 14.0
7 385031 1 1.000000 14.0
8 391681 3 0.999998 14.0
9 492771 2 1.000000 14.0

# Dataframe dfB
index x y category
0 56345 3 1.000000 6.0
1 383741 4 1.000000 6.0
2 103044 2 1.000000 6.0
3 297357 5 1.000000 6.0
4 257508 3 1.000000 6.0
5 223600 2 0.999938 6.0
6 44530 2 1.000000 6.0
7 82925 3 1.000000 6.0
8 169592 3 0.500000 6.0
9 229482 4 0.285714 6.0

我的代码片段如下所示:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style="darkgrid")

# Set up the figure
f, ax = plt.subplots(figsize=(8, 8))

# Draw the two density plots
ax = sns.kdeplot(dfA.x, dfA.y,
cmap="Reds", shade=True, shade_lowest=False)
ax = sns.kdeplot(dfB.x, dfB.y,
cmap="Blues", shade=True, shade_lowest=False)

为什么数据帧 dfA 中的数据没有实际绘制?

最佳答案

我认为高斯 KDE 不太适合您的任何一个数据集。您有一个具有离散值的变量和一个大多数值似乎都是常数的变量。这不能通过二元高斯分布很好地建模。

至于到底发生了什么,如果没有完整的数据集,我不能肯定地说,但我预计 KDE 带宽(特别是在 y 轴上)最终会变得非常非常窄,以至于密度不可忽略的区域很小。您可以尝试设置更宽的带宽,但我的建议是对这些数据使用不同类型的绘图。

关于python - Seaborn kdeplot 没有绘制一些数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39113224/

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