seaborn kde plot 中的级别是什么意思?

What does levels mean in seaborn kde plot?

我正在尝试绘制二维数据的等高线图。但是,我想手动输入轮廓。我在 seaborn.kde documentation 中找到了“级别”选项,我可以在其中手动定义等高线的级别。但是,我不知道这些级别是什么意思。文档给出了这个定义 -

Levels correspond to iso-proportions of the density.

等比例密度是什么意思? 有没有我可以阅读的参考资料?

基本上,绘制对应于 0.05 的 level 等高线,使得 5% 的分布位于它“下方”。或者,因为全密度的积分等于 1(这就是它成为 PDF 的原因),等高线以外区域的积分将为 0.05。

这里的level描述了低于给定阈值的累积质量。如 documentation.

中的示例所述

Number of contour levels or values to draw contours at. A vector argument must have increasing values in [0, 1]. Levels correspond to iso-proportions of the density: e.g., 20% of the probability mass will lie below the contour drawn for 0.2. Only relevant with bivariate data

您可以用两种方式描述关卡 -

  1. 指定概率质量函数中您想要的分区数(levels = 5 生成 4 条等高线,将概率质量函数分为 5 个部分)
  2. 明确提及每个轮廓的阈值作为向量

这里所说的分区描述的是等高线图以外的区域。因此,0.2 意味着 20% 的概率质量位于代表 20% 的第一个等高线之外。尝试使用以下代码可以使这一点更加清晰。

我在下面展示了两种实现方式,供您参考。

import seaborn as sns
geyser = sns.load_dataset("geyser",)

#Levels as equal cuts in the probability mass function
sns.kdeplot(
    data=geyser, x="waiting", y="duration", hue="kind",
    levels=5
)

#Levels as explicitly described cuts in the probability mass function
sns.kdeplot(
    data=geyser, x="waiting", y="duration", hue="kind",
    levels=[0.3, 0.4, 0.8]
)