Created
January 20, 2018 22:34
-
-
Save fhiyo/3bfe1b894ffbdf8afcd78794da800fa3 to your computer and use it in GitHub Desktop.
KaggleのTitanicチュートリアルをrandom forestで試したもの (前処理少しやった)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Random forestを用いたtitanicのチュートリアル問題\n", | |
"\n", | |
"18/01/21\n", | |
"データの前処理を少し行っている.Ageの欠損値を敬称によって補完した." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"- [Titanic Top 4% with ensemble modeling | Kaggle](https://www.kaggle.com/yassineghouzam/titanic-top-4-with-ensemble-modeling)\n", | |
"- [タイタニック号データ分析:Feature Engineering](http://rindalog.blogspot.jp/2016/10/feature-engineering.html)\n", | |
"- [Exploring Survival on the Titanic | Kaggle](https://www.kaggle.com/mrisdal/exploring-survival-on-the-titanic/code)\n", | |
"- [Kaggleのtitanic問題で上位10%に入るまでのデータ解析と所感 - mirandora.commirandora.com](http://www.mirandora.com/?p=1804)←cross valicationで精度を評価してた\n", | |
"\n", | |
"を参考にしながら書いている." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import math\n", | |
"import re\n", | |
"\n", | |
"import pandas as pd\n", | |
"import matplotlib.pyplot as plt\n", | |
"import seaborn as sns\n", | |
"%matplotlib inline\n", | |
"\n", | |
"from sklearn.ensemble import RandomForestClassifier\n", | |
"\n", | |
"sns.set(style='white', context='notebook', palette='deep')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Load training and test data\n", | |
"train_df = pd.read_csv(\"../input/train.csv\", header=0)\n", | |
"test_df = pd.read_csv(\"../input/test.csv\", header=0)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"データの前処理を行うが,先にどのようなアルゴリズムを使うかを決めないと前処理の方向性も決まらない? \n", | |
"例えば,Decision Treeを使うならCategorical Dataをそのままにしてもよいが,他のLabeled Dataを陽に扱えない手法を用いるなら \n", | |
"ダミー変数化するなどの処理が必要になる." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>PassengerId</th>\n", | |
" <th>Survived</th>\n", | |
" <th>Pclass</th>\n", | |
" <th>Name</th>\n", | |
" <th>Sex</th>\n", | |
" <th>Age</th>\n", | |
" <th>SibSp</th>\n", | |
" <th>Parch</th>\n", | |
" <th>Ticket</th>\n", | |
" <th>Fare</th>\n", | |
" <th>Cabin</th>\n", | |
" <th>Embarked</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>3</td>\n", | |
" <td>Braund, Mr. Owen Harris</td>\n", | |
" <td>male</td>\n", | |
" <td>22.0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>A/5 21171</td>\n", | |
" <td>7.2500</td>\n", | |
" <td>NaN</td>\n", | |
" <td>S</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n", | |
" <td>female</td>\n", | |
" <td>38.0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>PC 17599</td>\n", | |
" <td>71.2833</td>\n", | |
" <td>C85</td>\n", | |
" <td>C</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>3</td>\n", | |
" <td>1</td>\n", | |
" <td>3</td>\n", | |
" <td>Heikkinen, Miss. Laina</td>\n", | |
" <td>female</td>\n", | |
" <td>26.0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>STON/O2. 3101282</td>\n", | |
" <td>7.9250</td>\n", | |
" <td>NaN</td>\n", | |
" <td>S</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>4</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n", | |
" <td>female</td>\n", | |
" <td>35.0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" <td>113803</td>\n", | |
" <td>53.1000</td>\n", | |
" <td>C123</td>\n", | |
" <td>S</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>5</td>\n", | |
" <td>0</td>\n", | |
" <td>3</td>\n", | |
" <td>Allen, Mr. William Henry</td>\n", | |
" <td>male</td>\n", | |
" <td>35.0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" <td>373450</td>\n", | |
" <td>8.0500</td>\n", | |
" <td>NaN</td>\n", | |
" <td>S</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" PassengerId Survived Pclass \\\n", | |
"0 1 0 3 \n", | |
"1 2 1 1 \n", | |
"2 3 1 3 \n", | |
"3 4 1 1 \n", | |
"4 5 0 3 \n", | |
"\n", | |
" Name Sex Age SibSp \\\n", | |
"0 Braund, Mr. Owen Harris male 22.0 1 \n", | |
"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n", | |
"2 Heikkinen, Miss. Laina female 26.0 0 \n", | |
"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n", | |
"4 Allen, Mr. William Henry male 35.0 0 \n", | |
"\n", | |
" Parch Ticket Fare Cabin Embarked \n", | |
"0 0 A/5 21171 7.2500 NaN S \n", | |
"1 0 PC 17599 71.2833 C85 C \n", | |
"2 0 STON/O2. 3101282 7.9250 NaN S \n", | |
"3 0 113803 53.1000 C123 S \n", | |
"4 0 373450 8.0500 NaN S " | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"train_df.head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Convert \"Sex\" to be a dummy variable (female = 0, Male = 1)\n", | |
"train_df[\"Sex\"] = train_df[\"Sex\"].map({\"female\": 0, \"male\": 1}).astype(int)\n", | |
"test_df[\"Sex\"] = test_df[\"Sex\"].map({\"female\": 0, \"male\": 1}).astype(int)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"PassengerId 0\n", | |
"Survived 0\n", | |
"Pclass 0\n", | |
"Name 0\n", | |
"Sex 0\n", | |
"Age 177\n", | |
"SibSp 0\n", | |
"Parch 0\n", | |
"Ticket 0\n", | |
"Fare 0\n", | |
"Cabin 687\n", | |
"Embarked 2\n", | |
"dtype: int64" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# 欠損値が含まれているデータの数がいくつあるかを項目ごとに調べる\n", | |
"train_df.isnull().sum()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# 外れ値を検出して除外している参考記事もあったが,今回は無視" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Name, Ticket, Cabinが非構造データ.どう処理をする?" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"https://www.kaggle.com/mrisdal/exploring-survival-on-the-titanic/notebook\n", | |
"にあるように,乗客の名前から分かることは結構あるようだ. \n", | |
"例えば,敬称がMrsだったら結婚している女性のものなので女性で年齢は未婚の人よりも高い傾向あることが予想できる.\n", | |
"というわけで,名前から敬称(Titleというらしい?)を抜き出して属性として使えるようにしよう." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Palsson, Master. Gosta Leonard\n", | |
"Rice, Master. Eugene\n", | |
"Uruchurtu, Don. Manuel E\n", | |
"Panula, Master. Juha Niilo\n", | |
"Goodwin, Master. William Frederick\n", | |
"Skoog, Master. Harald\n", | |
"Moubarek, Master. Gerios\n", | |
"Caldwell, Master. Alden Gates\n", | |
"Nicola-Yarred, Master. Elias\n", | |
"Byles, Rev. Thomas Roussel Davids\n", | |
"Bateman, Rev. Robert James\n", | |
"Sage, Master. Thomas Henry\n", | |
"Panula, Master. Eino Viljami\n", | |
"Goldsmith, Master. Frank John William \"Frankie\"\n", | |
"Rice, Master. Arthur\n", | |
"Lefebre, Master. Henry Forbes\n", | |
"Asplund, Master. Clarence Gustaf Hugo\n", | |
"Becker, Master. Richard F\n", | |
"Navratil, Master. Michel M\n", | |
"Minahan, Dr. William Edward\n", | |
"Carter, Rev. Ernest Courtenay\n", | |
"Asplund, Master. Edvin Rojj Felix\n", | |
"Rice, Master. Eric\n", | |
"Allison, Master. Hudson Trevor\n", | |
"Moraweck, Dr. Ernest\n", | |
"Navratil, Master. Edmond Roger\n", | |
"Coutts, Master. William Loch \"William\"\n", | |
"Aubart, Mme. Leontine Pauline\n", | |
"Goodwin, Master. Sidney Leonard\n", | |
"Pain, Dr. Alfred\n", | |
"Richards, Master. William Rowe\n", | |
"Dodge, Master. Washington\n", | |
"Peuchen, Major. Arthur Godfrey\n", | |
"Goodwin, Master. Harold Victor\n", | |
"Coutts, Master. Eden Leslie \"Neville\"\n", | |
"Butt, Major. Archibald Willingham\n", | |
"Davies, Master. John Morgan Jr\n", | |
"Duff Gordon, Sir. Cosmo Edmund (\"Mr Morgan\")\n", | |
"Kirkland, Rev. Charles Leonard\n", | |
"Stahelin-Maeglin, Dr. Max\n", | |
"Sagesser, Mlle. Emma\n", | |
"Simonius-Blumer, Col. Oberst Alfons\n", | |
"Frauenthal, Dr. Henry William\n", | |
"Weir, Col. John\n", | |
"Moubarek, Master. Halim Gonios (\"William George\")\n", | |
"Crosby, Capt. Edward Gifford\n", | |
"Moor, Master. Meier\n", | |
"Hamalainen, Master. Viljo\n", | |
"Rothes, the Countess. of (Lucy Noel Martha Dyer-Edwards)\n", | |
"Brewe, Dr. Arthur Jackson\n", | |
"Rice, Master. George Hugh\n", | |
"Dean, Master. Bertram Vere\n", | |
"Leader, Dr. Alice (Farnham)\n", | |
"Carter, Master. William Thornton II\n", | |
"Thomas, Master. Assad Alexander\n", | |
"Skoog, Master. Karl Thorsten\n", | |
"Reuchlin, Jonkheer. John George\n", | |
"Panula, Master. Urho Abraham\n", | |
"Mallet, Master. Andre\n", | |
"Richards, Master. George Sibley\n", | |
"Harper, Rev. John\n", | |
"Andersson, Master. Sigvard Harald Elias\n", | |
"Johnson, Master. Harold Theodor\n", | |
"Montvila, Rev. Juozas\n" | |
] | |
} | |
], | |
"source": [ | |
"# Mrとかの有名な敬称じゃない名前を抽出してみる\n", | |
"for name in train_df['Name']:\n", | |
" print(name) if not re.search('(miss)|(mrs)|(ms)|(mr)\\.', name, re.IGNORECASE) else '' " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Uruchurtu, Don. Manuel E\n", | |
"Byles, Rev. Thomas Roussel Davids\n", | |
"Bateman, Rev. Robert James\n", | |
"Carter, Rev. Ernest Courtenay\n", | |
"Aubart, Mme. Leontine Pauline\n", | |
"Peuchen, Major. Arthur Godfrey\n", | |
"Butt, Major. Archibald Willingham\n", | |
"Kirkland, Rev. Charles Leonard\n", | |
"Sagesser, Mlle. Emma\n", | |
"Simonius-Blumer, Col. Oberst Alfons\n", | |
"Weir, Col. John\n", | |
"Crosby, Capt. Edward Gifford\n", | |
"Rothes, the Countess. of (Lucy Noel Martha Dyer-Edwards)\n", | |
"Reuchlin, Jonkheer. John George\n", | |
"Harper, Rev. John\n", | |
"Montvila, Rev. Juozas\n" | |
] | |
} | |
], | |
"source": [ | |
"# MasterとかDr.が多い?これらを入れて再度出力\n", | |
"for name in train_df['Name']:\n", | |
" print(name) if not re.search('(miss)|(mrs)|(ms)|(mr)|(master)|(dr)\\.', name, re.IGNORECASE) else '' " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"とりあえず名前を並べてみて,多く使われている敬称は取り除けたけど,その分布とかはこの方法だとわからない.\n", | |
"ので敬称の頻度分布がわかるようにしてみる." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0 Mr\n", | |
"1 Mrs\n", | |
"2 Mr\n", | |
"3 Mr\n", | |
"4 Mrs\n", | |
"Name: Title, dtype: object" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Nameから敬称を抽出する.データを見る限り,\"名字 敬称 名前\"の順になっていたのでそのルールに沿って敬称を取得する\n", | |
"train_df_title = [i.split(\",\")[1].split(\".\")[0].strip() for i in train_df[\"Name\"]]\n", | |
"train_df[\"Title\"] = pd.Series(train_df_title)\n", | |
"# train_df[\"Title\"].head()\n", | |
"\n", | |
"test_df_title = [i.split(\",\")[1].split(\".\")[0].strip() for i in test_df[\"Name\"]]\n", | |
"test_df[\"Title\"] = pd.Series(test_df_title)\n", | |
"test_df[\"Title\"].head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEtCAYAAAAWZydGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xm8XdP5x/HPvYmIVBJTzGOLR6uqqCFIRcsvYmiUIqVFSjVtqqiWVqNC66eG0ipqilkHU6taQ9QYSlVRlD7Kj6qSlmpiqiHJ/f3xrCM7x73rnmnnnlzf9+uVV87Z9+x11jln7/Wsaa/d0dXVhYiISE86+zoDIiLS3hQoREQkS4FCRESyFChERCRLgUJERLIG9nUG6mVmiwIbA88Bc/o4OyIiC4sBwArAH9z9jXp2XOgCBREkpvd1JkREFlKjgDvq2WFhDBTPAVx66aUsv/zyfZ0XEZGFwowZM9hrr70glaH1WBgDxRyA5ZdfnpVXXrmv8yIisrCpu8teg9kiIpKlQCEiIlkKFCIikqVAISIiWQoUIiKSpUAhIiJZChQiIpK1MF5H8bbnf3xJU/uP+OJnWpQTEZH+Sy0KERHJUqAQEZEsBQoREckqdYzCzO4DXkpPnwTOAn4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NSrcdGhl4tqGF4hprzdWbhbUbisVt4IGs0VEapSCxFDiPiIXE4FiAnEL234ZJECBQkSkV8U1mICliFvNPkzcSOxcYE0zG9ofgwToOgoRkV6lMYnhxDUO/yDuTvcXYGNgCWLxzsuIBfv6HY1RiIj0wMz2Bf4AzACuIW4iNpO4X/2RRNDYkLjx1MN9lM3SKVCIiHQjLeR3BHFf6g8BVxPL/3+PWJjvUGIa7H/Luld1u9AYhYhIFTP7GDAMOB6YCywCPJEW5ZsMLA0c5+5P9fcgARqjEBHpzjPEnej+DJxOlJUfN7OX3P0BM/sSsWDfu4IChYjIOz1OjD9sTLQojie6mvZINxi6ry8zt6Cp60lEpIq7zwU+DewDfB/4AHE70/8AT/VdzvqGBrNFRDLMbAciWDxILPk9o4+ztMApUIiI9MLM3k/Mbnqqr/PSFxQoREQkS2MUIiKSpUAhIiJZChQiIpKlQCEiIlkKFCIikqUrs0VqYGanA1sAg4A1gcp9kM8Cutz9TDM7H5ji7n8zs6eA0e/W6ZTSvyhQiNTA3ScBmNnqwK3u/uFuXrY1cPSCzJfIgqBAIdIEM5uSHr5O3MzmWjMbVfj7AOBE4k5oA4AL3P2UBZxNkaZojEKkBdz9e8CzwPbu/u/Cnz6f/r4hsAkwrhhIRBYGalGIlGsb4MPp/gYAiwPrAdP7Lksi9VGgECnXAOAwd78KwMyWAV7t2yyJ1EddTyKtM5t3Vr5uBj5vZouY2eLAHcCmCzxnIk1Qi0KkdX5NDGaPKWw7E1gLuJ84385391v7IG8iDdPqsSIikqWuJxERyVKgEBGRLAUKERHJUqAQEZEsBQoREclSoBARkSwFChERyVKgEBGRrP8HjZTi0OpCohwAAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10c927f28>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# 敬称の頻度分布を可視化\n", | |
"g = sns.countplot(x=\"Title\",data=train_df)\n", | |
"g = plt.setp(g.get_xticklabels(), rotation=45) " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"上の可視化の結果を見る限り,Mr, Mrs, Miss, Masterの4つ以外はほとんど現れていないことがわかる.なのでまとめて'rare'のカラムにまとめてしまうことにする. \n", | |
"※ Mme, MlleはMissと同じ意味の敬称らしいので,同じカテゴリに分類しておく(本当か怪しいが,Mme, Mlleはデータ数が少ないので間違っていても大きく影響は受けないだろう).Msは婚姻状態によらない女性の敬称. \n", | |
"MrsとMissは女性が既婚ならMrs, 未婚ならMissの敬称になる.昔の慣習と言った感じだが,年齢とは相関がありそうなので使わせてもらう." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# 敬称をカテゴリデータに変換する.本当はonehot-vectorの形にしたほうがよさそう\n", | |
"train_df[\"Title\"] = train_df[\"Title\"].replace(['Lady', 'the Countess','Countess','Capt', 'Col','Don', 'Dr', 'Major', 'Rev', 'Sir', 'Jonkheer', 'Dona'], 'Rare')\n", | |
"train_df[\"Title\"] = train_df[\"Title\"].map({\"Master\":0, \"Miss\":1, \"Mme\":1, \"Mlle\":1, \"Ms\" : 2 , \"Mrs\":2, \"Mr\":3, \"Rare\":4})\n", | |
"train_df[\"Title\"] = train_df[\"Title\"].astype(int)\n", | |
"\n", | |
"test_df[\"Title\"] = test_df[\"Title\"].replace(['Lady', 'the Countess','Countess','Capt', 'Col','Don', 'Dr', 'Major', 'Rev', 'Sir', 'Jonkheer', 'Dona'], 'Rare')\n", | |
"test_df[\"Title\"] = test_df[\"Title\"].map({\"Master\":0, \"Miss\":1, \"Mme\":1, \"Mlle\":1, \"Ms\" : 2 , \"Mrs\":2, \"Mr\":3, \"Rare\":4})\n", | |
"test_df[\"Title\"] = test_df[\"Title\"].astype(int)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "i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31br7iXmZeU9E3A30ZubdXShXGhaDQGpDZs4BiIjdgesz87WDzLY/VXca0phiEEjPQUTMqwefoHpg6KqImN4yfTzwBaCXqmOxBZn5pQ6XKQ3JawTSKMjM/6DqvfWQAX3qvL+evidV52OzWoNC2hzYIpCaNRN4bUQcUL/ejqqzscE6BZS6wiCQmjUeODkzvwtQ90L7WHdLkjbmqSFp9KzlmQdX1wLvj4itImI7YCkwteOVSUOwRSCNniupLhYf1DKu/5fqbqX6e5v/XH7nWWqCvY9KUuE8NSRJhTMIJKlwBoEkFc4gkKTCGQSSVDiDQJIKZxBIUuH+Hy54WV5UCS/LAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10c9636d8>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"g = sns.countplot(train_df[\"Title\"])\n", | |
"g = g.set_xticklabels([\"Master\",\"Miss/Mme/Mlle\", \"Ms/Mrs\",\"Mr\",\"Rare\"])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAAEYCAYAAACHjumMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAFfZJREFUeJzt3X+UVXW5x/H3zDAIgqiIKzU19JpP3hI1TdHSgLFUyiyzm0rX9BpqirrMlWl6EzS1pdmPycofld7U/JW6AkrLRMRIiWtledHHLLWsrPBXKgMDzNw/vnvoMJ45s+fHM3vO5vNay8Xss8/Z59ly5sN377P392no7OxERCRCY9EFiEh5KWBEJIwCRkTCKGBEJIwCRkTCKGBEJMyIqA2bWSPwDWA3YBXwCXd/smL9Z4CjgH8Cl7r7/KhaRKQY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+23eTfh8mDmZhpQwYd/8D6TDoNOCG7OFxwAfd/aPAqaR9byCNSh5w9xbgNtJQnWwdpCHwTdlf4CHZc17I1oX/IvSwL5VmAie5+7uBPUi/oCcAs7PHGkiHgoWoUX/l/7thU281OfehcFnYfQz4FnAG8JK7zyBNlbJxNgKDf9X9OHBf9tmeRjpZ/PvBrKmUAZO5BdjO3Z/IltcAr5nZYuAe0o2T2wD/C1xgZgtIw8ivZc9fZmY3AFcBb8n+df058EwB5we670ul3wIPZPX/HVhCOuSbb2b3AluRDjuKVKt+GH71VtPbPgwL7r4MaAXeBhxsZouAbwK/I33eK80DXjWzB4CHgU53f2Uw69GtAiISpswjGBEpmAJGRMIoYEQkjAJGRMIoYEQkTBlvFZACmdnXSe1oRgI7kW4FgPR1f6e7X2lm15Kue3nGzJ4Gprj70wWUK8EUMDKo3P0UADObCCx0992rPG0qMGco65JiKGBkSJjZ7OzHlaQLvn5kZvtXrG8CLgOmkG68u87dvzzEZcog0zkYGVLu/gXSHdPTu93HMzNb/3bSzXmHVQaQ1CeNYGS4OBDY3cymZctjSTfjVbvBU+qEAkaGiybgLHe/AyC7Y/21YkuSgdIhkhRhDa//x20BMNPMms1sLKnR3j5DXpkMKo1gpAjzSSd5D6p4rGvWwF+RPpfXuvvCAmqTQaS7qUUkjA6RRCSMAkZEwihgRCSMAkZEwihgRCSMAkZEwihgRCTM/wOhcWDfLV8lsQAAAABJRU5ErkJggg==\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x10ca8fc50>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"g = sns.factorplot(x=\"Title\",y=\"Survived\",data=train_df,kind=\"bar\")\n", | |
"g = g.set_xticklabels([\"Master\",\"Miss\",\"Mrs\",\"Mr\",\"Rare\"])\n", | |
"g = g.set_ylabels(\"survival probability\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Mrの敬称がついている(男性)は生存率が低い.Masterは男児につける敬称らしい. \n", | |
"グラフを見る限り,女性,子供が優先的に救助されたという話と一致した結果になっている.\n", | |
"敬称がRareになっている人はいろんな属性の人が混ざっているのであろうから,全体の真ん中くらいの生存率なのも自然な気がする." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Nameの属性を削除\n", | |
"train_df.drop(labels = [\"Name\"], axis = 1, inplace = True)\n", | |
"test_df.drop(labels = [\"Name\"], axis = 1, inplace = True)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"次に欠損値の扱いについてだが,Cabinは欠損している数が多いので今回はデータから除外する. \n", | |
"Ageはその値が生存に関わっているようなので (前回でAgeとSurviveの間には相関があることがわかっている), \n", | |
"Ageの欠損値を適当な値で埋める. \n", | |
"今回,名前から敬称を抽出したので,それを使って年齢の補完を行う.\n", | |
"knnとかで補完したほうがよさそうだが,今回は単に中央値で補完する." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"3.5\n", | |
"21.0\n", | |
"35.0\n", | |
"30.0\n", | |
"48.5\n" | |
] | |
} | |
], | |
"source": [ | |
"print(train_df[train_df.Title==0].Age.dropna().median())\n", | |
"print(train_df[train_df.Title==1].Age.dropna().median())\n", | |
"print(train_df[train_df.Title==2].Age.dropna().median())\n", | |
"print(train_df[train_df.Title==3].Age.dropna().median())\n", | |
"print(train_df[train_df.Title==4].Age.dropna().median())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# fillnaで各行のTitleなどの属性によって補完値を変えるやり方がわからなかったので,forで回す\n", | |
"# 補完する値をmedianにしたら精度が前回よりも下がったが,理由は不明.\n", | |
"for i, train in train_df.iterrows():\n", | |
" if math.isnan(train.Age):\n", | |
" if math.isnan(train.Title):\n", | |
" train_df.at[i, 'Age'] = train_df[train_df.Title==train.Title].Age.dropna().mean()\n", | |
" else:\n", | |
" train_df.at[i, 'Age'] = train_df.Age.dropna().mean()\n", | |
"\n", | |
"for i, test in test_df.iterrows():\n", | |
" if math.isnan(test.Age):\n", | |
" if math.isnan(test.Title):\n", | |
" test_df.at[i, 'Age'] = test_df[test_df.Title==test.Title].Age.dropna().mean()\n", | |
" else:\n", | |
" test_df.at[i, 'Age'] = test_df.Age.dropna().mean()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"PassengerId 0\n", | |
"Survived 0\n", | |
"Pclass 0\n", | |
"Sex 0\n", | |
"Age 0\n", | |
"SibSp 0\n", | |
"Parch 0\n", | |
"Ticket 0\n", | |
"Fare 0\n", | |
"Cabin 687\n", | |
"Embarked 2\n", | |
"Title 0\n", | |
"dtype: int64" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"train_df.isnull().sum()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# XXX: 今回はとにかく属性を削除しまくる\n", | |
"train_df = train_df.drop([\"Ticket\", \"SibSp\", \"Parch\", \"Fare\", \"Cabin\", \"Embarked\"], axis=1)\n", | |
"test_df = test_df.drop([\"Ticket\", \"SibSp\", \"Parch\", \"Fare\", \"Cabin\", \"Embarked\"], axis=1)\n", | |
"\n", | |
"# Prepare data\n", | |
"X_train = train_df.drop(['PassengerId', 'Survived'], axis=1).values\n", | |
"y_train = train_df.Survived.values\n", | |
"X_test = test_df.drop('PassengerId', axis=1).values\n", | |
"\n", | |
"model = RandomForestClassifier(n_estimators=100)\n", | |
"\n", | |
"# Predict with \"Random Forest\"\n", | |
"y_pred = model.fit(X_train, y_train).predict(X_test).astype(int)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"メモ: 欠損値についての考え方が書いてあった.\n", | |
"[Python pandas 欠損値/外れ値/離散化の処理 - StatsFragments](http://sinhrks.hatenablog.com/entry/2016/02/01/080859#%E6%AC%A0%E6%90%8D%E5%80%A4)\n", | |
"#### 欠損発生のパターンと概要\n", | |
"- MCAR\tランダムに欠損している ( 欠損は \"IQ\" や \"JobPerformance\" の値に関係しない )\n", | |
"- MAR\t他の変数の値と関係して欠損している ( \"IQ\" が低いと \"JobPerformance\" の欠損が多い )\n", | |
"- MNAR\t欠損が発生しているデータ自身と関係して欠損している ( \"JobPerformance\" の真の値が低いと \"JobPerformance\" の欠損が多い )" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"accuracy: 0.802\n" | |
] | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"from sklearn.model_selection import KFold\n", | |
"from sklearn.metrics import accuracy_score\n", | |
"\n", | |
"# cross valicationで性能を予測\n", | |
"SPLIT_NUM = 4\n", | |
"sum_ = 0\n", | |
"kf = KFold(n_splits=SPLIT_NUM, shuffle=True)\n", | |
"for train, cv in kf.split(X_train):\n", | |
" y_cv_pred = model.fit(X_train[train], y_train[train]).predict(X_train[cv]).astype(int)\n", | |
" sum_ += accuracy_score(y_train[cv], y_cv_pred, normalize=True)\n", | |
"\n", | |
"print('accuracy: {:.3f}'.format(sum_/SPLIT_NUM))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Save prediction to csv file\n", | |
"submission = pd.DataFrame({\n", | |
" \"PassengerId\": test_df[\"PassengerId\"],\n", | |
" \"Survived\": y_pred\n", | |
" })\n", | |
"submission.to_csv('../output/submission.csv', index=False)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# score: 0.71" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment