python - Seaborn Factorplot的源函数是什么

标签 python pandas plot machine-learning seaborn

我是数据科学新手。我有一个关于简单的 seaborn 因子图的问题。线段代表什么?

这是我的测试。

import pandas as pd
import seaborn as sns

x3 = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
y3 = [0, 1, 1, 1, 0, 3, 1, 0, 1, 1, 3, 2, 3, 2, 3, 3, 2, 3, 2, 2]
data = {'x': x3, 'y': y3}
test3 = pd.DataFrame(data)
sns.factorplot(x='Pclass', y='Survived', data=test3)

结果是

enter image description here

通过这个简单的测试,我知道图中的每个点都表示具有相同值的所有 x 值的 y 的平均值(exp)。例如,当 x = 1 时,我们有 (1, 0)、(1, 3)、(1, 3) 和 (1, 3),因此平均值为 (0 + 3 + 3 + 3)/4 = 2.25。但是我不知道为什么x = 1的线段是从0.75到3.0,为什么不是[0.0, 3.0]?

我尝试在网上查找 Factorplot 源代码或任何有用的解释或文档,但没有得到好的结果。

谁能帮帮我,非常感谢。

最佳答案

我使用 github repo 顶部的“搜索此存储库”搜索栏对此进行了调查。 .

搜索“factorplot”让我找到 seaborn/categorical.pyclass _CategoricalPlotter(object) ,这导致我_BarPlotter(_CategoricalStatPlotter) ,其文档字符串“”“用条形显示点估计和置信区间。”“”,它是 __init__包括self.estimate_statistic(estimator, ci, n_boot) .

estimate_statistic(self, estimator, ci, n_boot)的函数定义位于class _CategoricalStatPlotter(_CategoricalPlotter) (仍在 categorical.py 文件中)。那里有一个空列表 confint (即置信区间)被初始化并填充:

 boots = bootstrap(stat_data, func=estimator,
                                      n_boot=n_boot,
                                      units=unit_data)
 confint.append(utils.ci(boots, ci))

所以你提到的垂直误差线是 bootstrapped confidence intervals .

关于python - Seaborn Factorplot的源函数是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43725372/

相关文章:

Python Brainf*** – while 循环中的错误

python - 对于不一致的日期范围,用零填充 pandas groupby

python - 如何过滤包含 NaN 的 bool 掩码

python - matplotlib 3d 曲面图不显示

r - 将 `curve` 与列表中的函数一起使用

r - 抖动 geom_line()

python - error_perm : 550 Permission denied

python - 类对象的选择性比较

用于消费的python kafka不起作用

python - Pandas 将列重复到新行中