科学の箱

科学・IT・登山の話題

Python

kaggle Titanic Tutorial – 6

投稿日:2018年5月27日 更新日:

さて、今回は年齢について検証する。まずこれまでは中央値を使っていたわけだ。これをもともと年齢分布と中央値を使って更新した後の年齢分布を比較する。


import numpy as nm
import pandas as pd
import seaborn as sns
%matplotlib inline

d_train = pd.read_csv('train.csv')
d_train['Age_1'] = d_train['Age']

fig, (axis1,axis2) = plt.subplots(1,2,figsize=(15,4))
axis1.set_title('Original Age')
axis2.set_title('Update Null with Mean')

d_train["Age_1"] = d_train["Age_1"].fillna(29.69911764705882)
d_train['Age'].hist(bins=70, ax=axis2)
d_train['Age_1'].hist(bins=70, ax=axis4)

この結果は以下のようになります。

わかりにくいのですが更新前は22歳で最大値が50であったのに対して、更新後は29歳で200になっています。この結果として分布図が極端に変化しています。

明らかに更新した年齢は実体にそぐわないものになっています。

そこでこちらを参考にして他のデータを参考にしてAgeを保管する。

https://ahmedbesbes.com/how-to-score-08134-in-titanic-kaggle-challenge.html


d_train = pd.read_csv('train.csv')
d_train['title'] = d_train['Name'].apply(get_title).map(Title_Dictionary)
d_train['FamilySize'] = d_train['SibSp'] + d_train['Parch'] + 1
d_train_g = d_train_g = d_train.groupby(['Sex','Pclass','title', 'FamilySize'])
d_train_g_m = d_train_g.median()
d_train_g_m.reset_index()[['Sex', 'Pclass', 'title', 'FamilySize', 'Age']]

性別、Class, title, FamilySizeにより年齢が全く異なるのがわかる。

次回はこの結果を利用してAgeを補完する。

メタ情報

inarticle



メタ情報

inarticle



-Python
-,

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

scikit-learnで適切なアルゴリズムを選択するためのチートシート

  http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html Related posts:matplot …

no image

タプルの操作

タプルはPythonで提供されているデータ構造の一つ。タプルは固定長で変更できない複数の値の集合である。 タプルオブジェクト (tuple object) — Python 3.8.0 ドキュメント …

no image

Scrapy – Install

インストールガイドはこちら https://doc.scrapy.org/en/latest/intro/install.html#intro-install anacondaにインストールする co …

no image

Pillowのインストールは成功しているのにエラーが出る

from . import _imaging as core ImportError: DLL load failed: The specified module could not be found …

no image

requests.exceptions.SSLError: HTTPSConnectionPoolの対応方法

エラー raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host=&#8217 …

2018年5月
« 4月   6月 »
 123456
78910111213
14151617181920
21222324252627
28293031  

side bar top



アーカイブ

カテゴリー