首页 > 解决方案 > 面网格和点图没有给出准确的结果

问题描述

我正在使用Kaggle的 Titanic 数据集。我试图可视化所有分类变量之间的相关性。为此,我将点图与 FaceGrid 一起使用。图的某些部分与数据相矛盾。

为了生成点图,我使用了

grid = sns.FacetGrid(train, row='Embarked', size=2.2, aspect=1.6)
grid.map(sns.pointplot, 'Pclass', 'Survived', 'Sex', palette='deep')
grid.add_legend()

点图显示,几乎所有从“C”出发且 Pclass =1 和 2 的男性都幸存了下来。这是极不可能的。我尝试使用数据透视表对其进行验证:

temp = round(pd.pivot_table(train_df, values='Survived', index=['Embarked','Sex'], columns='Pclass', aggfunc=[lambda x: len(x), np.sum,'mean'] ),2)

1班42人,2班10人,3班43人从'C'出发。

但只有 17、2、10 人幸存下来。因此,平均概率应为 0.40、0.20 和 0.23。

我认为主要问题是它产生的警告:

UserWarning: Using the pointplot function without specifying `order` is likely to produce an incorrect plot.
UserWarning: Using the pointplot function without specifying `hue_order` is likely to produce an incorrect plot.

点图和数据透视表

我不明白Order这里的意思。附带说明:如何对 Embarked 索引进行排序以说出“S”、“C”和“Q”。

标签: python-3.xpandasseaborn

解决方案


推荐阅读