Kaggleで使えそうなSeaborn
こんにちは!Kaggleを始めて、最初に眺めてるTitanicのKernelで、可視化に使えるSeabornについて説明します。
Seabornとは
Seabornでは、Pythonのデータ可視化ライブラリです。
Pandasで整型したデータを楽に可視化して、Kaggleでは学習・特徴量エンジニアリング前の分析時に有効。
Kaggleの初心者向けCompetitions「Titanic」
参考にしたのは以下のKernelです。
とりあえずKaggleでデータをダウンロードして、データの可視化を進めていきます。
本題!
年齢と生存率の関係
grid = sns.FacetGrid(train, col='Survived') #col_wrap=1行あたりの表示要素数 grid.map(plt.hist, 'Age', bins=20)
年齢・生存率・チケットクラスの関係
grid = sns.FacetGrid(train, col='Survived', row='Pclass', size=2.2, aspect=1.6) grid.map(plt.hist, 'Age', alpha=.5, bins=20)
発着港・生存率・性別の関係
grid = sns.FacetGrid(train, row='Embarked', size=2.2, aspect=1.6) grid.map(sns.pointplot, 'Pclass', 'Survived', 'Sex', palette='deep') grid.add_legend()
発着港と生存率の関係
survive = train[['Embarked', 'Survived']].groupby('Embarked').mean()['Survived'].sort_values() print(survive) plt.figure(figsize=(7,3)) plt.subplot(111) sns.barplot(survive.index, survive, color='blue')
チケットクラスと生存率の関係
survive = train[['Pclass', 'Survived']].groupby('Pclass').mean()['Survived'].sort_values() print(survive.index) plt.figure(figsize=(7,3)) plt.subplot(111) sns.barplot( survive.index, survive, color='yellow')