2015-06-11 19:17:52 +08:00
{
"cells": [
2015-06-19 09:07:36 +08:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<small><i>This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/data-science-ipython-notebooks).</i></small>"
]
},
2015-06-11 19:17:52 +08:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# matplotlib-applied\n",
"\n",
"* Applying Matplotlib Visualizations to Kaggle: Titanic\n",
"* Bar Plots, Histograms, subplot2grid\n",
"* Normalized Plots\n",
"* Scatter Plots, subplots\n",
"* Kernel Density Estimation Plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Applying Matplotlib Visualizations to Kaggle: Titanic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Prepare the titanic data to plot:"
]
},
{
"cell_type": "code",
2015-07-08 10:50:52 +08:00
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import pandas as pd\n",
"import numpy as np\n",
"import pylab as plt\n",
"import seaborn\n",
"\n",
"# Set the global default size of matplotlib figures\n",
"plt.rc('figure', figsize=(10, 5))\n",
"\n",
"# Set seaborn aesthetic parameters to defaults\n",
"seaborn.set()"
]
},
{
"cell_type": "code",
"execution_count": 2,
2015-06-11 19:17:52 +08:00
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df_train = pd.read_csv('../data/titanic/train.csv')\n",
"\n",
"def clean_data(df):\n",
" \n",
" # Get the unique values of Sex\n",
" sexes = np.sort(df['Sex'].unique())\n",
" \n",
" # Generate a mapping of Sex from a string to a number representation \n",
" genders_mapping = dict(zip(sexes, range(0, len(sexes) + 1)))\n",
"\n",
" # Transform Sex from a string to a number representation\n",
" df['Sex_Val'] = df['Sex'].map(genders_mapping).astype(int)\n",
" \n",
" # Get the unique values of Embarked\n",
" embarked_locs = np.sort(df['Embarked'].unique())\n",
"\n",
" # Generate a mapping of Embarked from a string to a number representation \n",
" embarked_locs_mapping = dict(zip(embarked_locs, \n",
" range(0, len(embarked_locs) + 1)))\n",
" \n",
" # Transform Embarked from a string to dummy variables\n",
" df = pd.concat([df, pd.get_dummies(df['Embarked'], prefix='Embarked_Val')], axis=1)\n",
" \n",
" # Fill in missing values of Embarked\n",
" # Since the vast majority of passengers embarked in 'S': 3, \n",
" # we assign the missing values in Embarked to 'S':\n",
" if len(df[df['Embarked'].isnull()] > 0):\n",
" df.replace({'Embarked_Val' : \n",
" { embarked_locs_mapping[np.nan] : embarked_locs_mapping['S'] \n",
" }\n",
" }, \n",
" inplace=True)\n",
" \n",
" # Fill in missing values of Fare with the average Fare\n",
" if len(df[df['Fare'].isnull()] > 0):\n",
" avg_fare = df['Fare'].mean()\n",
" df.replace({ None: avg_fare }, inplace=True)\n",
" \n",
" # To keep Age in tact, make a copy of it called AgeFill \n",
" # that we will use to fill in the missing ages:\n",
" df['AgeFill'] = df['Age']\n",
"\n",
" # Determine the Age typical for each passenger class by Sex_Val. \n",
" # We'll use the median instead of the mean because the Age \n",
" # histogram seems to be right skewed.\n",
" df['AgeFill'] = df['AgeFill'] \\\n",
" .groupby([df['Sex_Val'], df['Pclass']]) \\\n",
" .apply(lambda x: x.fillna(x.median()))\n",
" \n",
" # Define a new feature FamilySize that is the sum of \n",
" # Parch (number of parents or children on board) and \n",
" # SibSp (number of siblings or spouses):\n",
" df['FamilySize'] = df['SibSp'] + df['Parch']\n",
" \n",
" return df\n",
"\n",
"df_train = clean_data(df_train)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bar Plots, Histograms, subplot2grid"
]
},
{
"cell_type": "code",
2015-07-08 10:50:52 +08:00
"execution_count": 3,
2015-06-11 19:17:52 +08:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.text.Text at 0x11357ac50>"
2015-06-11 19:17:52 +08:00
]
},
2015-07-08 10:50:52 +08:00
"execution_count": 3,
2015-06-11 19:17:52 +08:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
2015-07-08 10:50:52 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlMAAAJZCAYAAACN2rCOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3X9ck+X+P/DXPTZUGIgUeT6nCI3ILIEiocAfoVlRKUfU\npYhQqYV6KpU0ZyrzZ/4WTS09Zp1PUxPSafbofDodUaMgxdKTelTqQ0pYiihobOA22PX9w6/3B0KG\nuuHceD0fjx4PuDeu+33fa5ev3buu+5KEEAJEREREdEMUri6AiIiIyJ0xTBERERE5gGGKiIiIyAEM\nU0REREQOYJgiIiIicgDDFBEREZEDlK4uwFOdOnUKTz75JLp06QIAsNlsUCqVSEtLw8CBAx1qe+TI\nkVi2bBkCAgLQt29frFy5Eg8++KAzyrYrPT0dCQkJSEpKavTYunXr8Pnnn0MIAZvNhp49eyIjIwMq\nlcop+37llVcwZcoUhIaGXvffarVa3HfffRg5cmSjx8rKypCVlYX//Oc/UCgUaNOmDdLT0/HEE084\no+xGVq1aha5du7ZY+0Qt6Y/9GgAIIZCWlobBgwe7sLKW1Vw/cf/992Pv3r0ICAhosRrMZjPee+89\nfPXVVxBCoK6uDomJiXj55ZdbZH979uzBoUOH8Prrr7dI+56GYaoFtW3bFtu3b5d//+233/Diiy/C\nx8cHTz311A23W1BQgPq3B7tZtwqTJAmSJDXa/j//8z/Izc1FTk4OvL29YbFY8Prrr2PVqlWYOHGi\nU/b9t7/97Yb/tqm6KyoqMGzYMEycOBELFiwAABw/fhwjR46Ej48PYmNjb3ifTdm3bx/CwsKc3i7R\nzfLHfq2srAwDBgxAt27dGoQsT+GKfuKPhBAYN24c7rnnHmRnZ8Pb2xsXLlxAeno6qqurMX78eKfv\n8/Dhw7h48aLT2/VUDFM30Z///Ge8/vrrWL9+PZ566ilYLBYsWbIE3333Herq6vDAAw9g2rRpUKvV\n2L17N9auXQur1YqKigoMHD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yEi7NT/44IPy\nvxcPPPAAvvzySwCX++wr/Xbv3r3xyiuv4PTp04iLi8Mbb7zRbP/a2jBM3WSHDx9uMCh9+vTp6NWr\nFwDAZDLBbDajuroaAwcOxFNPPYXu3btjyJAh2LlzZ5OBRKls+DL+8XnNtXcl3AFoEBIkSWrQlpeX\n11X3/7e//Q3R0dF4+OGHERwcjCFDhuD777/H6NGjrxqmLBZLg7/38fGRfx40aBCSkpKg0WhQVVWF\n6OjoBs+VJAmDBw/G9u3b4e3tDY1GA+ByR/n2229j5MiR6NevH+655x7s2LHjqvVe8dBDD+Hf//43\nUlJSGmzfvHkzLl26hE6dOjX6G5vNhrq6OqhUqgbHZLVaGzyvTZs2DWq+2ms3dOhQ9OnTB/n5+fj6\n66+xatUq7Nixg50U3dLatGnTYMxUfZs2bcInn3yCESNGIDExEQEBAfLXThMnTsSQIUOQn5+Pbdu2\nYd26dTAYDE1ut9lsWLFiBe655x4Al7/2r98/XXmPXdkmhIBKpWoQfOo/v7n26vdD9TXXT7z44ost\ncvz1a3vooYfw0UcfwWazNQiAhw4dwoYNG6DT6RqEnyvHW1tb2+iD3x/7qvr9f1PCw8ORm5uLgoIC\n7N27FxqNBqtXr5aDIvHWCDfViRMn8N577+Gll14CAPTq1QsbNmyAxWKBzWaDTqdDVlYWfvnlF5hM\nJowfPx7x8fHYt28fLBaL/MnEy8ur0RvCnpKSErvtNaVXr17Izs4GcPn7+G+//faqz7NYLFi6dKk8\nRgoAiouL0a1bNwBAYGA
2015-06-11 19:17:52 +08:00
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.figure.Figure at 0x113145b10>"
2015-06-11 19:17:52 +08:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Size of matplotlib figures that contain subplots\n",
"figsize_with_subplots = (10, 10)\n",
"\n",
"# Set up a grid of plots\n",
"fig = plt.figure(figsize=figsize_with_subplots) \n",
"fig_dims = (3, 2)\n",
"\n",
"# Plot death and survival counts\n",
"plt.subplot2grid(fig_dims, (0, 0))\n",
"df_train['Survived'].value_counts().plot(kind='bar', \n",
" title='Death and Survival Counts',\n",
" color='r',\n",
" align='center')\n",
"\n",
"# Plot Pclass counts\n",
"plt.subplot2grid(fig_dims, (0, 1))\n",
"df_train['Pclass'].value_counts().plot(kind='bar', \n",
" title='Passenger Class Counts')\n",
"\n",
"# Plot Sex counts\n",
"plt.subplot2grid(fig_dims, (1, 0))\n",
"df_train['Sex'].value_counts().plot(kind='bar', \n",
" title='Gender Counts')\n",
"plt.xticks(rotation=0)\n",
"\n",
"# Plot Embarked counts\n",
"plt.subplot2grid(fig_dims, (1, 1))\n",
"df_train['Embarked'].value_counts().plot(kind='bar', \n",
" title='Ports of Embarkation Counts')\n",
"\n",
"# Plot the Age histogram\n",
"plt.subplot2grid(fig_dims, (2, 0))\n",
"df_train['Age'].hist()\n",
"plt.title('Age Histogram')"
]
},
{
"cell_type": "code",
2015-07-08 10:50:52 +08:00
"execution_count": 4,
2015-06-11 19:17:52 +08:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.text.Text at 0x1138e6f10>"
2015-06-11 19:17:52 +08:00
]
},
2015-07-08 10:50:52 +08:00
"execution_count": 4,
2015-06-11 19:17:52 +08:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
2015-07-08 10:50:52 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAegAAAFeCAYAAABOw4xkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtclHXe//H3jIAgh9QazdIlI1L3TvwthfeSZuTPjLY0\nDDHxmGabluXKqmGKaK2r2Sp2sNtT5UYHdQvN3LtuS23phhI76KPW0jRTLFMUtZmRmMGZ3x/+nCQV\nVBjm6/h6Ph4+HsM11+FzfcB5X6e5LovX6/UKAAAYxRroAgAAwKkIaAAADERAAwBgIAIaAAADEdAA\nABiIgAYAwEAhgS4AaGibNm3SnDlzdPjwYXm9Xl1++eV69NFHdc0119TL/JcuXaqffvpJf/zjH+tl\nfmeje/fumjt3rhISEs5r+uzsbBUXF6t58+bVhi9atEg2m63O9aWlpSk/P1/vvfee1qxZo/nz55/1\ntB988IHmz5+viooKHTt2TNdcc40mTpyoli1bat26dSouLtbkyZPrXCNgGgIaFxWXy6UHHnhAS5Ys\nUYcOHSRJq1at0v33369169bJYrHUeRn9+/ev8zzOR11uaWCxWDRs2DANGzasHiv6xcqVK89run37\n9ik7O1srVqxQq1atJEnz58/XmDFjtHTpUnXv3l3du3evz1IBYxDQuKhUVFTI4XDI6XT6hvXu3VvR\n0dGqqqrSZ599pr/85S96++23JUkbNmzw/fzss89q06ZNKisrU3x8vD799FM999xzuu666yRJY8eO\nVefOnXXgwAEdPnxY3bt318yZM33z+umnn9SjRw+tXbtWP/74ox5//HEdOXLEF45paWnasGGDpk+f\nriZNmujnn3/WK6+8oscee0y7d++W1WrVf/zHf+jxxx8/7YbE0qVLNW3aNLlcLg0bNkzp6emaPHmy\nLr30Uo0dO1bS8Y2RNWvW6Lnnnjtl+jMF/M6dO/X444+roqJC+/fvV/v27TV37lyFhYWpY8eOGjZs\nmNavXy+n06nx48fr3Xff1bZt29SiRQvNnz9fERERat++vT7++GPfPPfu3as77rhDhYWFioqKktfr\nVWpqqp555hm1a9fON96hQ4fkdrur/b6GDh3q27gqKCjQmjVr9Pzzz6tPnz6+vhw+fFjl5eUqKSmR\n2+3W9OnTtW3bNlVVVSk5OVkTJkxQo0aNzuIvBggczkHjonLJJZdo/PjxGjFihHr06KEJEybozTff\nVHJyskJDQ2udfu/evVq5cqVmz56t9PR0rVixQpJ05MgRFRcXq1evXrJYLLJYLOrSpYuOHj2qL7/8\nUpK0evVqpaSkqEmTJho1apSGDh2qVatWadGiRcrLy9OmTZskSdu3b1deXp5Wrlyp999/X0ePHtXK\nlSv1xhtvSJL27Nlz2toiIiJUUFCgF198UbNnz9b27ds1aNAgFRQUyOPxSJKWL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JC1157rZo3b64ffvhB5eXl8nq9ev/992ucX79+/bRw4UJVVlbqd7/7naTqQdeyZUsl\nJCRoypQp6tevnySpbdu2Cg0N1Xvvvedb/po1a9SlS5dTQvK1117TxIkT1bVrV40bN0433XTTGff+\nCgoKJEk//PCDPvroIyUnJ0uSbrvtNn311Vd67733lJ6efi7tkiQVFRXpwQcf1O233y5J2rx5s44d\nO3bO8/k1i8WiAQMGaNKkSerVq1e1oD8hKipKeXl51TZqdu/ercaNGys2NrbauNOmTdOxY8c0ZcqU\nasO7du2qJUuWyOv1yuVy6aGHHtJrr71W5/oBf2MPGheVtm3bat68eXr66af1ww8/KCIiQtHR0Xri\niSd01VVXSTp+qDg9PV02m00pKSm+aU+cWz5Z9+7dNW3atGp7bL8er1+/fhozZozvq0WhoaGaN2+e\npk+frmeffVbHjh3T6NGj1blzZ23YsKHa/Pv06aONGzfqD3/4gyIiInTllVdq6NChp103t9utPn36\nqKqqSjk5Ob4ACw0N1W233aaDBw+qadOmZ+zNmfYqx44dq9GjR+uyyy5Tq1at1LNnT+3evfuUaU7X\nn1/P+9fvp6Wl6cknnzzjle//+Z//qZycHD322GM6cuSIQkJC1LJlSz3//POKjo72zW/Tpk1avny5\n2rdvr759+/o2dKZPn67Jkydr+vTp6t27t9xut7p06aIRI0acsQ+AKSw8bhIIbkePHtWgQYM0derU\n8/6etL/885//1FtvvaWFCxcGuhTAOLXuQS9YsEDr16+X2+3WoEGDlJiYqOzsbFmtVsXHxys3N1cW\ni0XLly/XsmXLFBISolGjRlXb8wAQGB9++KHGjRun9PR048J58ODBKi8v1zPPPBPoUgAj1bgHvWHD\nBr300kuaP3++jh49qsWLF+urr77S8OHDlZSUpNzcXN10003q1KmThg8froKCAlVWViozM1Nvvvnm\nac8pAQCA2tW4B11UVKR27drpwQcflMPh0IQJE/TGG28oKSlJktStWzcVFRXJarUqMTFRoaGhCg0N\nVWxsrLZu3aqOHTs2yEoAABBsagzo8vJy7d27VwsWLFBpaalGjhxZ7SrTyMhI2e12ORwORUdHVxt+\nNt8pBQAAp1djQDdr1kxxcXEKCQlR27Zt1bhxY+3fv9/3vsPhUExMjKKioqrduMDpdComJqbGBXu9\nXr6LCADAGdQY0Ndff71efvllDRs2TPv27dPPP/+s3//+9yopKVHnzp1VWFio5ORkJSQkKC8vTy6X\nS5WVldqxY4fi4+NrXLDFYlFZmb1eVwanstmi6bOf0WP/o8f+R48bhs0WXftI/1+NAZ2SkqKNGzeq\nb9++8ng8ys3N1ZVXXqmcnBy53W7FxcUpNTVVFotFQ4YM0YABA+TxeJSVlcUFYgAA1EFAvwfN1pr/\nsVXsf/TY/+ix/9HjhnE
2015-06-11 19:17:52 +08:00
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.figure.Figure at 0x1132fcd90>"
2015-06-11 19:17:52 +08:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Get the unique values of Embarked and its maximum\n",
"family_sizes = np.sort(df_train['FamilySize'].unique())\n",
"family_size_max = max(family_sizes)\n",
"\n",
"df1 = df_train[df_train['Survived'] == 0]['FamilySize']\n",
"df2 = df_train[df_train['Survived'] == 1]['FamilySize']\n",
"plt.hist([df1, df2], \n",
" bins=family_size_max + 1, \n",
" range=(0, family_size_max), \n",
" stacked=True)\n",
"plt.legend(('Died', 'Survived'), loc='best')\n",
"plt.title('Survivors by Family Size')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Normalized Plots"
]
},
{
"cell_type": "code",
2015-07-08 10:50:52 +08:00
"execution_count": 5,
2015-06-11 19:17:52 +08:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.text.Text at 0x113ccbc50>"
2015-06-11 19:17:52 +08:00
]
},
2015-07-08 10:50:52 +08:00
"execution_count": 5,
2015-06-11 19:17:52 +08:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
2015-07-08 10:50:52 +08:00
"image/png": "iVBORw0KGgoAAAANSUhE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CZHnu/7p169SvXz+1aNFCgwcPVo8ePbRnz54y/Z1Q+THyRoXXuHFjzZkzRzNmzNDRo0dVrVo1\nBQQEKCEhQX/9618lSb1791avXr0UFBSk8PBw13stFkuRs9E7deqkV199VQMHDixxvZiYGA0dOlTz\n5s2TdPGkrfDwcD3yyCMKCgpSy5Yt1bx5cx08eLDQKPGPijsT/pVXXlFUVJQ2btyof/zjH/rnP/+p\n+fPnKzAwUA8//LAOHDggSbr//vs1YcIESXKdgNa7d29ZLBbVr19fSUlJxW4vNDRUY8aM0cmTJ9Wk\nSRNXG5LUo0cPTZ48+arPri+p3jp16ui5555T//795e/vL19fX02cOLHE+ZI0bdo0JSQkqHv37nI4\nHIqMjFRkZKQOHz5c5HO7ND1o0CBNmDBB3bt3l81mU926dVWtWrUyt3e5kJAQzZs3T2+88YYmT54s\np9OpunXrav78+a6T3C69vzz23+l0asOGDYqMjFT16tVVu3ZtJSQkXNXfC5WXxSjLcT8Apvbll1/q\ns88+01tvveXtUq7KV199pRo1auiBBx6Q0+nUkCFD1L59e49e6gdURB4/bL5jxw7FxcUVmZ+amqro\n6GjFxsZq6dKlni4DuO7FxcVp7ty5rhPwzKhp06aaN2+eevTooe7duys4OFiPPfaYt8sCyp1HR95v\nv/22Pv/8c9WoUaPQDSk
2015-06-11 19:17:52 +08:00
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.figure.Figure at 0x113b53b90>"
2015-06-11 19:17:52 +08:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2015-07-08 10:50:52 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFxCAYAAABa5SD+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8jXf+///nyUkiOLFEMbUWVVo1SFFapmgsUaUqItOK\npbSd0doq8xPDBFUStXQQSjfTKg2mpNP0Yyyl9KPqo0MUpRSNPUJiyUnESc71/cOvZ5omkQQnJ1c8\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KmICA\nAO3bt0/Sf0epBQkKCtL+/fu1evXqAq9WDw0N1TvvvKOsrCzXqH379u0aPHiwevfurYCAAH3zzTe5\ngqQoKlWqpPHjxys2NlbJycn67rvv1Lx5cw0ZMkStW7fO9TlZrVbX/rZs2VJJSUnatWuXJOnQoUPq\n0aNHgfu5du1aSTfCJikpyXWEoH///tq0aZN++OEH10i6OG5W77hx4/Q///M/6tmzp6KiomSz2XT2\n7Nl85587d04dOnTQqlWrlJ6eLkmKjY1VZGSka1u//WJksVjUoUMH7dixQ8nJyZKk1atXu5YXt71f\ntGzZUg0aNFB0dLTrvPSFCxc0bdq0XAFrGMYd3X+UPYy8USIKOnTn6+urRYsWafr06XrvvfeUnZ2t\n0aNHq1WrVtq5c2eR2g0LC1NERISeeeYZVapUSU8++aSWLl0qwzBc2/Xx8SlwO781f/58zZo1S927\nd1eFChXkdDrVtWtXvfL
2015-06-11 19:17:52 +08:00
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.figure.Figure at 0x113c19f10>"
2015-06-11 19:17:52 +08:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2015-07-08 10:50:52 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFxCAYAAABa5SD+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl0FGW+xvGnu5OwdViCIQ6yGBSDg14WQUFFZScsgUAI\nGSUsAjoXZJPMBYQbNjEBBEcIKi6gIBhghKhxGBAB8SIyKIKAIogYwhaWBCQL0EnX/YNDD5GEDphO\np8L3c47npKuq3/pV8R6ffmu1GIZhCAAAmIbV2wUAAIAbQ3gDAGAyhDcAACZDeAMAYDKENwAAJkN4\nAwBgMoQ3vOrIkSNq0KCB+vbte8288ePHq0GDBjp79ux12xg3bpwWLlx4Q+vNzMzUxIkT1a1bN3Xv\n3l3h4eFauXLlDbVxPWlpaYqKirrp77dp00Z79+69Zvq4ceP02GOPqUePHurRo4fCwsLUrl07vf32\n227bTE1N1YgRI264lgYNGujMmTM3/L0r2rRpo06dOqlHjx4KDw9X165dFRcXp7J8l+rFixf197//\nXeHh4erRo4e6deumt956yzU/Ojpaa9eu9WKFMDsfbxcAlCtXTr/++quOHTummjVrSpKys7P17bff\nymKxuP2+xWIp0nJXmz17tux2uz755BNJ0smTJ9WnTx/dcccdevjhh298I34nKChIiYmJf7id37NY\nLBo4cKAGDhzomnb8+HF17txZbdu2VXBwcKHfPXbsmA4dOnRT6/2jQTt79mw1bNhQkuRwOBQdHa1l\ny5bpqaee+kPtlkaGYWjo0KGqV6+eli9fLj8/P509e1bPPvuscnJyXD+gbrTPAldj5A2vs1qt6ty5\nsytIJWndunVq27atKzScTqdefPFFRUZGqkuXLurcubN27NjhWv7KcgcPHtSgQYPUs2dP9ejRQx9+\n+GGB6zx9+rQuXLggh8MhSapRo4YSEhJUp04dSZdHi3v27HEtf2UkfOTIET3++OMaNGiQOnbsqPHj\nx2vatGmu5TZv3qzIyEgdPXpUTZo0kWEYevzxx/O1NXr0aCUmJur06dMaOnSooqKi1LZtW0VHRys9\nPd3t/vp9kB4/flySVKlSJUnSG2+8od69eyssLEzt27fX+vXr5XQ6NXHiRB0+fFiDBw+WJO3YsUNP\nPfWUevbsqV69emnTpk2FrvPVV1917dMryw0cOFArVqxwLfP6668rLi7Obf2+vr5q2rSp64dEQfVK\nl/8to6Ki1LNnT/Xs2VPLli277vQrNVypc9iwYTp58qSkyyPdOXPmqG/fvmrTpo3+53/+x7UfV61a\npdDQUIWHhys+Pt71I8Nde8OHD1eXLl20dOnSfNu3fft2HTp0SC+88IL8/PwkSVWrVtXMmTPVvHnz\na/ZHcW4/biEG4EWpqalG48aNjT179hidO3d2TR8wYICxf/9+IyQkxMjIyDB27NhhjBw50jV/wYIF\nxrPPPmsYhmGMGzfOWLhwoZGbm2t07tzZ2Lt3r2EYhvHbb78ZoaGhxs6dO69Z7759+4wOHToYTZs2\nNQYNGmTMnz/fOHTokGt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XXntN\n06dP19tvv63c3FyNHDnSFZZXmzt3rmbNmqWOHTuqYsWKcjqdat++vYYNGybp8mHeyZMna/ny5WrY\nsKHuu+++a+q9ws/PT126dNHWrVt1//33F7hcmzZtNGXKFA0ZMsQ1bdiwYZo5c6YWLFiggIAAdezY\nUSkpKUXeX1d069ZNK1as0MyZM/XCCy9o3bp16tq1q6pWrarOnTsrOTlZ2dnZuueee2Sz2RQZGakV\nK1a49sHFixfldDo1a9a
2015-06-11 19:17:52 +08:00
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.figure.Figure at 0x113cc3d90>"
2015-06-11 19:17:52 +08:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"pclass_xt = pd.crosstab(df_train['Pclass'], df_train['Survived'])\n",
"\n",
"# Normalize the cross tab to sum to 1:\n",
"pclass_xt_pct = pclass_xt.div(pclass_xt.sum(1).astype(float), axis=0)\n",
"\n",
"pclass_xt_pct.plot(kind='bar', \n",
" stacked=True, \n",
" title='Survival Rate by Passenger Classes')\n",
"plt.xlabel('Passenger Class')\n",
"plt.ylabel('Survival Rate')\n",
"\n",
"# Plot survival rate by Sex\n",
"females_df = df_train[df_train['Sex'] == 'female']\n",
"females_xt = pd.crosstab(females_df['Pclass'], df_train['Survived'])\n",
"females_xt_pct = females_xt.div(females_xt.sum(1).astype(float), axis=0)\n",
"females_xt_pct.plot(kind='bar', \n",
" stacked=True, \n",
" title='Female Survival Rate by Passenger Class')\n",
"plt.xlabel('Passenger Class')\n",
"plt.ylabel('Survival Rate')\n",
"\n",
"# Plot survival rate by Pclass\n",
"males_df = df_train[df_train['Sex'] == 'male']\n",
"males_xt = pd.crosstab(males_df['Pclass'], df_train['Survived'])\n",
"males_xt_pct = males_xt.div(males_xt.sum(1).astype(float), axis=0)\n",
"males_xt_pct.plot(kind='bar', \n",
" stacked=True, \n",
" title='Male Survival Rate by Passenger Class')\n",
"plt.xlabel('Passenger Class')\n",
"plt.ylabel('Survival Rate')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Scatter Plots, subplots"
]
},
{
"cell_type": "code",
2015-07-08 10:50:52 +08:00
"execution_count": 6,
2015-06-11 19:17:52 +08:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.text.Text at 0x113f4d710>"
2015-06-11 19:17:52 +08:00
]
},
2015-07-08 10:50:52 +08:00
"execution_count": 6,
2015-06-11 19:17:52 +08:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
2015-07-08 10:50:52 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmgAAAJoCAYAAADS7x1JAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XlclOX6x/HPsAkIShjapmYezTweLbc0l8yDuyiILC64\n5ZLl0dxNBcXllJp5TO1nVqZpCRVoZprr6VBqLpV5bNVOuaShpSIoyDLz+2OGQRhcAJ0Zm+/79ZqX\nzjXMw8UF+lzcz3Pft8FkMpkQEREREafh5ugERERERKQwNWgiIiIiTkYNmoiIiIiTUYMmIiIi4mTU\noImIiIg4GTVoIiIiIk5GDZqI3LADBw7Qr18/unXrRkhICEOGDOHIkSM37fgJCQksW7bsph3vRrRt\n25aDBw+W6Rg//PADderUuSW5T5o0idatWxMaGkpYWBghISE8/fTTnD17FjDn/80331zzGAcPHmTa\ntGk3PTcRuXU8HJ2AiNwesrOzGTZsGCtWrOChhx4CYP369QwZMoQdO3ZgMBjK/Dmio6PLfIzSKOty\nkGvWrCEkJIR33nmHJ598End395uUGRgMBgYOHMjAgQOtsTlz5jB9+nRefvnlGzrGkSNHSE1NvWk5\nicitpxE0EbkhmZmZZGRkcPHiRWusW7duxMXFkZuby549ewgJCbG+duXzRYsW8eSTT9KtWzfGjh1L\nmzZtOHTokPVjR48ezZo1a1i0aBEzZ85k586dhY514cIFmjZtSnp6OocPHyYmJoZu3brRvXt31q1b\nZ/183bp1Izo6mtDQUDIyMhg5ciShoaH06NGD2NjYqzZiCQkJ9OjRg65du5KUlATA1KlTWbBggfVj\n1q9fz4gRI2zem5GRwYcffshTTz2Fv78/H3/8caGaTZgwgQ4dOhAREcGkSZN47rnnAEhNTWXEiBH0\n6NGDbt268eqrr97w96JZs2b8/PPPNvHExERCQkLo3r07Tz75JL/88gunTp3i5ZdfZv/+/UyePPmG\nP4eIOJYaNBG5IRUrVmT8+PEMHjyY4OBgJkyYQFJSEs2bN8fT0/O67z916hTr1q1j/vz5hIeHs3bt\nWgDS0tLYtWsXISEhGAwGDAYDLVq04NKlS9YmbsOGDbRp0wZfX1+GDx9O//79Wb9+Pa+99hoLFizg\nwIEDgHmkaMGCBaxbt45t27Zx6dIl1q1bx/vvvw/AiRMnis3Nx8eH5ORkli9fzvz58zly5Ah9+/Yl\nOTkZo9EImJufXr162bx3/fr11KhRg5o1axIaGsrKlSutr73yyisYjUY2b97Mm2++yXfffWd9bfz4\n8YSHh5OcnMx7773Hzp072bRpU7H5XdlYZmVlsW7dOh599NFCH7N7927eeOMN3nrrLT744AO6du3K\nM888w913382oUaNo3Lgx//znP6/9TRIRp6EGTURu2IABA9i1axdTp04lKCiI1157zTpadT0NGjTA\nzc38X054eDibNm0iJyeHDRs20LZtW/z8/DCZTNZmpGfPntYmLjk5mYiICH7++Weys7MJDg4GoHLl\nyrRv355PP/0Ug8HAXXfdxd133w1A48aNOXLkCDExMSxbtoz+/ftTtWrVYnOLioqyHq9ly5bs3r2b\nOnXqcN999/Hvf/+bn376iTNnztCiRQub965Zs4bQ0FAAQkJC+Oabb6wNY0pKCj179gTAz8+PsLAw\nwDyytm/fPhYuXEhoaChRUVGkpqby/fff2xzfZDKxYsUKQkNDCQ0NJSIigsDAQMaOHVvoYz799FM6\nd+7MHXfcAUBYWBipqamcOHGizJdwRcT+dA+aiNyQL774gq+++orBgwfTpk0b2rRpw5gxYwgJCWHX\nrl0EBAQUagRycnIKvd/X19f693vuuYe6devyySefsHbtWqZMm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iIiJucqYi8mekETQRERERJ6MRNBEREREn\nowZNRERExMnclrM4c3PzOHfukqPTuG3dcYev6lcGql/pqXZlo/qVjepXeqpd2QQF+Zf4PbflCJqH\nx83biNgVqX5lo/qVnmpXNqpf2ah+pafa2d9t2aCJiIiI/JmpQRMRERFxMmrQRERERJyMGjQRERER\nJ6MGTURERMTJqEETERERcTJq0EREREScjBo0ERERESejBk1ERETEyahBExEREXEyatBEREREnIwa\nNBEREREnowZNRERExMmoQRMRERFxMmrQRERERJyMGjQRERERJ6MGTURERMTJqEETERERcTJq0ERE\nREScjIe9P6HRaGTKlCn88ssvuLm5MXPmTNzd3Zk0aRJubm7UqlWLadOmYTAY7J2aiIiIiFOwe4P2\n2WefkZmZyZo1a9i1axcLFiwgNzeXMWPG0KRJE6ZNm8b27dsJDg62d2oiIiJyhaysLBISUvD396ZL\nl6Z4e3s7OiWXYfdLnN7e3qSnp2MymUhPT8fT05NvvvmGJk2aANC6dWt27dpl77RERETkCllZWURF\nrWXChG4MH96eqKi1ZGVlOTotl2H3Bq1hw4ZkZ2fTsWNH4uLiiImJwWQyWV/39fUlPT3d3mmJiIjI\nFRISUti9eyDgCXiye/cAEhJSHJ2Wy7D7Jc7XX3+dhg0bMnr0aH777Tf69etHbm6u9fWLFy9SoUKF\n6x4nKMj/Vqb5p6f6lY3qV3qqXdmofmWj+t04f3/by5n+/t6qoZ3YvUHLzMykfPnyAFSoUIHc3Fzq\n1q3L3r17adq0KSkpKTRv3vy6xzlzRqNspRUU5K/6lYHqV3qqXdmofmWj+pVMly5Nad78TXbvHgBA\n8+Yr6NIlTDUshdI0tQbTldcX7eDChQs899xznDt3jtzcXPr3789f//pXYmNjycnJoWbNmsyaNeu6\nszj1A1J6+k+qbFS/0lPtykb1KxvVr+Q0SeDmuC0atJtF/8hKT/9JlY3qV3qqXdmofmWj+pWealc2\npWnQtFCtiIiIiJNRgyY
2015-06-11 19:17:52 +08:00
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.figure.Figure at 0x113b53250>"
2015-06-11 19:17:52 +08:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Set up a grid of plots\n",
"fig, axes = plt.subplots(2, 1, figsize=figsize_with_subplots)\n",
"\n",
"# Histogram of AgeFill segmented by Survived\n",
"df1 = df_train[df_train['Survived'] == 0]['Age']\n",
"df2 = df_train[df_train['Survived'] == 1]['Age']\n",
"max_age = max(df_train['AgeFill'])\n",
"\n",
"axes[1].hist([df1, df2], \n",
" bins=max_age / 10, \n",
" range=(1, max_age), \n",
" stacked=True)\n",
"axes[1].legend(('Died', 'Survived'), loc='best')\n",
"axes[1].set_title('Survivors by Age Groups Histogram')\n",
"axes[1].set_xlabel('Age')\n",
"axes[1].set_ylabel('Count')\n",
"\n",
"# Scatter plot Survived and AgeFill\n",
"axes[0].scatter(df_train['Survived'], df_train['AgeFill'])\n",
"axes[0].set_title('Survivors by Age Plot')\n",
"axes[0].set_xlabel('Survived')\n",
"axes[0].set_ylabel('Age')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Kernel Density Estimation Plots"
]
},
{
"cell_type": "code",
2015-07-08 10:50:52 +08:00
"execution_count": 7,
2015-06-11 19:17:52 +08:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.legend.Legend at 0x113175ed0>"
2015-06-11 19:17:52 +08:00
]
},
2015-07-08 10:50:52 +08:00
"execution_count": 7,
2015-06-11 19:17:52 +08:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
2015-07-08 10:50:52 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAf0AAAFtCAYAAAANqrPLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xd4VGXa+PHvtEzapBdqIKEkNEGxobQgLCLqCysoiqgr\nK/x0XWyouCKKdNTXVZG1o2IBUddVVHB5g6AgEEWQIDVA6CF10jPt/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F8+eWX2Gw2HA4H//73v71/Xnwtz+OWW25hy5YtfPXVV94vWRkZGbzy\nyis1djGo0f7MzMxqX96EqIv09EWzs2zZMu66665qPRuLxcKECRN47733uPnmm7nlllsIDAykS5cu\nBAYGAnDfffexYMECRo8ejcvlonv37kybNq1G+Tqdjp9//tk7JK3T6YiPj+edd97xTge88MILzJo1\nixtuuAG73c7111/P9ddfz9GjR2v0uDw/33fffUyfPp3ly5djMBgYNmwYl19+OVu2bPHeM3DgQO+C\nxEmTJpGSkkJERES1Ff5nq29DTJ8+3Vtnm83GwIED+X//7/8BkJqayoIFC7Db7d52e8pOSkpi0aJF\nHDlyhNjYWBYsWOC9PnjwYKZPn86tt97aqPrdfffdzJgxgy+++ILIyEiGDh3K+vXrMRgM/OMf/+CR\nRx7BZDKh0+mYO3cuAQEBtb4+ffp05syZw4033ojdbufqq6/2Dn3X9jv585//zMGDBxk9ejTBwcG0\na9fO++fFl/LOFB4eztK
2015-06-11 19:17:52 +08:00
"text/plain": [
2015-07-08 10:50:52 +08:00
"<matplotlib.figure.Figure at 0x113175d50>"
2015-06-11 19:17:52 +08:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Get the unique values of Pclass:\n",
"passenger_classes = np.sort(df_train['Pclass'].unique())\n",
"\n",
"for pclass in passenger_classes:\n",
" df_train.AgeFill[df_train.Pclass == pclass].plot(kind='kde')\n",
"plt.title('Age Density Plot by Passenger Class')\n",
"plt.xlabel('Age')\n",
"plt.legend(('1st Class', '2nd Class', '3rd Class'), loc='best')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}