我是数据科学的新手。我有一个关于简单的seaborn factorplot的问题。这条线段代表什么意思?
这是我的测试。
import pandas as pdimport seaborn as snsx3 = [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)
结果是
通过这个简单的测试,我知道图表中的每个点代表的是y在所有相同x值下的平均值(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仓库顶部的“搜索此仓库”搜索栏进行了查找。
搜索“factorplot”让我找到了seaborn/categorical.py
和class _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))
所以你提到的垂直误差条是自助法置信区间。