【发布时间】:2016-03-19 19:11:27
【问题描述】:
我正在The Billionaire Characteristics Database 数据集上练习我的机器学习分类技能。
我使用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 和 seaborn 进行分组可能还没有实现。
【问题讨论】: