我在The Billionaire Characteristics Database數據集上練習了我的ML分類技能。使用sframe作爲數據源繪製boxplot
我使用sframe
來加載和操作數據,seaborn
用於可視化。
在數據分析的過程中,我想從seaborn
教程畫一個框陰謀分類變量分組,像這樣的:
在數據集中,有一個networthusbillion
數值變量和selfmade
分類變量這表明億萬富翁是self-made
或(s)他有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)
)來繪製它,使用與seaborn
的sframe
只是還沒有實現,所以也許分組。
我編輯了我的答案。看看它是否有幫助(雖然在這一點上它可能太hacky。) – absolutelyNoWarranty