我正在亿万富翁特征数据库数据集上练习我的 ML 分类技能。
我sframe
用于加载和操作数据以及seaborn
用于可视化。
在数据分析的过程中,我想绘制一个按类别变量分组的箱线图,就像seaborn
教程中的这个:
在数据集中,有一个networthusbillion
数值变量和selfmade
分类变量来说明亿万富翁是否有钱self-made
或他是否inherited
有钱。
当我尝试使用 绘制类似的箱线图sns.boxplot(x='selfmade', y='networthusbillion', data=data)
时,会引发以下错误:
---------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-17-f4bd651c2ae7> in <module>()
----> 1 sns.boxplot(x='selfmade', y='networthusbillion', data=billionaires)
/home/iulian/.virtualenvs/data-science-python2/lib/python2.7/site-packages/seaborn/categorical.pyc in boxplot(x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, fliersize, linewidth, whis, notch, ax, **kwargs)
2127 plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
2128 orient, color, palette, saturation,
-> 2129 width, fliersize, linewidth)
2130
2131 if ax is None:
/home/iulian/.virtualenvs/data-science-python2/lib/python2.7/site-packages/seaborn/categorical.pyc in __init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, fliersize, linewidth)
420 width, fliersize, linewidth):
421
--> 422 self.establish_variables(x, y, hue, data, orient, order, hue_order)
423 self.establish_colors(color, palette, saturation)
424
/home/iulian/.virtualenvs/data-science-python2/lib/python2.7/site-packages/seaborn/categorical.pyc in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
136 # See if we need to get variables from `data`
137 if data is not None:
--> 138 x = data.get(x, x)
139 y = data.get(y, y)
140 hue = data.get(hue, hue)
AttributeError: 'SFrame' object has no attribute 'get'
我尝试了以下表格来绘制箱线图 - 它们都没有达到结果:
sns.boxplot(x=billionaires['selfmade'], y=billionaires['networthusbillion'])
sns.boxplot(x='selfmade', y='networthusbillion', data=billionaires['selfmade', 'networthusbillion'])
但是,我可以使用 绘制箱线图sframe
,但不按以下方式分组selfmade
:
sns.boxplot(x=billionaires['networthusbillion'])
所以,我的问题是:有没有办法使用 ? 绘制按分类变量分组的箱形图sframe
?也许我做错了什么?
顺便说一句,我设法pandas.DataFrame
使用相同的语法 ( sns.boxplot(x='selfmade', y='networthusbillion', data=data)
) 来绘制它,所以使用sframe
with进行分组可能seaborn
还没有实现。