mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
429 lines
158 KiB
Plaintext
429 lines
158 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"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",
|
||
|
"execution_count": 7,
|
||
|
"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",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.text.Text at 0x10d8a2d90>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlMAAAJZCAYAAACN2rCOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XmcXFWZ8PFfyEpMJ5M4jYzKoCI+4oJCRAUVgiLICOIy\njo4rqODCIDOijkZ0NhBHwHlBGVSiBhX1HRgXlBeBicimiCCOMugDKGJcRqLdZCFItn7/OLehaLq7\nOrlVqa7q3/fzySdVt26fe+pW1+nnnvucc6YNDQ0hSZKkbbNDpysgSZLUzQymJEmSajCYkiRJqsFg\nSpIkqQaDKUmSpBoMpiRJkmqY0ekK9KqIeBTwM+BH1aYdgI3AGZn5uZplXwq8MjMHIuIXwEsz8wd1\nypzgcb8BnJ+Z547y2ruBvwamAdOBbwJLM3Nji459EXBCZv50G352OfDjzDx9lNceAZwM7A1sAf4I\nfDAzL6xX4zHr8gHgh+0qX2qnUdo1KN/5MzLzMx2p1HbQrJ2IiC3An2bmQBvrMAd4H/BC7m9nP5+Z\nH27T8V4IPD0z/6Ed5fcae6baa31m7lX9ewrwUuADEfHSmuUeRPkyAQw1PG63oerfA0TEy4EXA8/M\nzKcCTwMeD/xjqw6cmS/clkCqMla9+4HvAJdl5p5V3Y8BzomI5217bcf1XGBmm8qWtofGdm0v4C+A\n0yP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QMhWIbZiklmiWM3Uw8OOI+CownzIK7I0NI6wurvbZDFxT3efdGBG3USZhvH6U\nMiVpe3kKMDciLqG0d+8D9rYNk9RKzYKpfsoMzodR5u75Og8cqbQWWEAJtFaPsl2SOulu4NTM/FRE\n7E4ZodrINkxSbc2Cqd8
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10ce4af10>"
|
||
|
]
|
||
|
},
|
||
|
"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",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.text.Text at 0x10dd37850>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAegAAAFeCAYAAABOw4xkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH2lJREFUeJzt3X2cXVV97/HPTJJhIJkQxMOTxoiAS+yVyoN9AEvgCigV\ngtL6cKUiIE8KgV5F1KC5BUEQJEoQKSZiwKvtVao2wguLBiSYXotAqiD6gzQYphRkJE/DgMwkM/1j\n7ySTOJmZTM6Zs3Lm83698sqZvffZ+zcrcL57rb3O3k19fX1IkqS8NNe7AEmS9IcMaEmSMmRAS5KU\nIQNakqQMGdCSJGXIgJYkKUPj612ANNpSSn8GfBbYneIktR24KCIerdL+zwGmRMTnqrG/YR7zN8C7\nI+L+Eb5/AXAM0LHFquMj4pntKq7Y/1LgKOCdwF9FxInb8N63A5cAu1B8Zv0S+EhEPJVSOhE4JiIu\n3N4apdwY0BpTUko7AbdTfKj/e7nsFODOlNKrI2K7bwwQETdt7z5GoA9o2s73z4mIOVWqZzMRcTBA\nSmmb3pdS2gdYABwSEe3lslnAt4AjIuL7wPerWqyUCQNaY80uwK5A24YFEfGNlNIaYHxK6Qjg+oh4\nA0BK6agNP6eU/g74c2Av4BHgL4B3RsSD5bb/CPy4XL87sBC4NiIOKtdPAZYD+wKvBL4EvIwiHK+N\niK+Xx7sOeL6sdTrwVWB/oBd4EDhnKycS56aUbgBay/19LaU0D3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zwNwD33/IjrrruWrq7n+dSnLuaCC87lggvOZfnyZRv3f8YZp/CRj8zk8ccf\nq8nvaUBLknYolcoeXHX
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10cb96650>"
|
||
|
]
|
||
|
},
|
||
|
"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",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.text.Text at 0x10ca8e490>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFpCAYAAAC1YKAIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmcXXV9//HXTDJBsgAJBpUlgIAfqRpFkCUoS5GqZTFo\n1SLKJohY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VT0tLf3eNG1Y7HlLkka1MS8ZS/fiFTx192N0L1nJxi+fxE4f3o2HZ9/Nyj8Vd+9c8kA711//\nHZ544nGOPPJ9nHTSCXzzm1fzgQ+857l2zjvvC9x++22cdNIJPProHzjuuCN54oni/mK33vo/XHDB\nLLq6lvHpT/8jJ5/8EU4++SM88sjDAHzve9/h2GOP4JRTTuJ3v3torbfJ8JYkjWptm2zEdkdMZ/mj\ni/nd5fP47YV3siT/9MKFajrDHR0dnH/+v/H+9x/JDjvsyL33zueZZ55h/vxfsffeb3luuYMPPpQ5\nc24E4KabbuDQQw/jqqtms9tuu3PhhZfwiU98ki9/+fN0dnZy7bXf4rLLruLLX76AlpaWte59O2wu\nSRrVVnYsZ8xGY9lm5s4ALH9sCY9cfS9tkzZ6fqGe51++4hVbMnZsEY+HHHIYN910A0899RRvfvO+\njBnT+4CsFg488O189KPHc/DBM+nq6mL77V/JI488zPz587j55h8DsHTpEhYu/F+23Xb759p83ete\nT09PzQrXgOEtSRrVVjzRxVPzFrL9EdNpGdPKRlPGM2bjsYwd30b30pVs9NLxrGxfDpsXy7e2Pj8o\nvdtuu3PxxRfS3t7Oqaf+0wvanTBhIhGv5sILZ3HQQYcCsO222/PqV+/MgQe+nfb2Rfz4x3PYeutp\n/P73j7By5QrGjduIBx9
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x100532f90>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFxCAYAAABa5SD+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmcZfOd//FXdXe16AXd0hJb2/OJkXSCDtJim8RMFoQs\nkxGJLS1ChvzGMkNCJEx+ZMEgkbZE8AuZQZCIIIstBNEIYeRDE0zaVlEdvdGKrt8f5xRXqeVWd926\ndapfz8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Of6p99amCGY5+a0ssXr6EK706AiNgTmJCZ55S3fbyO\nYtf9DzLzqSGqRZKkSmt4eJcPc5hRvv5xzfSfU9zkQJIkDYB3WJMkqWIMb0mSKsbwliSpYgxvSZIq\nxvCWJKliDG9J0oj3zM2P8cj59zDnvLt55Id3s/jJZb+e+/TTT+aZZ55e5s+fcso3ueeeu5b589C8\nm7RIkjQkXnx2EfPzOTY5YEsAXnh6AU9c/iBx8FbL1N6hhx6+XPW0tPR407QBceQtSRrRRr9pDB3P\nv8hzdz9Jx/wlrPzWiWzy+enMOe9ulvy1uHvn/AfauOKKy3j66afYe+9PccghB3LxxRfymc988tV2\nTjnlm9x8840ccsiBPPHEY8ycuTdPP13cX+yGG37NaaedzKJFCznmmH/j0EO/wKGHfoFHH50DwJVX\nXsb+++/FYYcdwsMPP7Tc22R4S5JGtNZVVmL9vaax+Innefic2fzp9NuZn399/UI1g+H29nZOPfV7\nfPrTe7PRRhtz77338NJLL3HPPXex7bbbvbrcLrvsxrXXXg3ANdf8nN1224MLLjiP6dO34vTTZ3Hk\nkV/mO985iXnz5nHJJT/
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10cded610>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFxCAYAAABa5SD+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XecXXWd//HXpCFkAgQMKBqq8IFFUTAqgoAssjZAwMIi\nSDOIDd1F3UVFEFx/Ii5hBQtNBAvuiitIEbDQlCpFQFY+IYCAoQUSUykp8/vjnIHLOOVOmJs738nr\n+Xjkwb3nnPs9nzNzmPf9fk/r6OrqQpIklWNUuwuQJEmDY3hLklQYw1uSpMIY3pIkFcbwliSpMIa3\nJEmFGdPuArRyi4gNgfuA32XmTj3mfR84EHh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V+2XJ//68XJmluuQ+dGE5fr85Ik9WZEhff999/Hddddw3e/exYA99wzna9+\n9cucffa5y9Xepz71mRdXUEevN8aRJOlFGVHD5p2dnTz22GNcfPEvmDXrcTbddDPOOOMcPvnJj/Dg\ngw8AcMEFP+Oss07n0Ucf4YAD9uHwww/j3HN/wP77v/+5dqZN+zrXXHMVhx9+GA8++BemTj2ARx+t\n7iFz5ZW/4ZvfPJGFCxdwyikn8fCF07n3+7fy1GMLAHjiDzOZ/t2buO8Hf+TpR4bXnXokSSPDiArv\nSZPW4fjjT+TOO2/nox89hP32ex/XXnsNHS/oAT//evbs2Zx00rf54AcPYJNNXsXtt9/Gs88+y223\n3cL22+/w3HK77bYHl112CQCXXnoxe+yxF+eccxZbbvlq1ttjM165x+bMvChZsvBZnrj+ITb9yBQ2\n2v+11arsfEuShtiIGja
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10ded4b50>"
|
||
|
]
|
||
|
},
|
||
|
"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",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.text.Text at 0x10c4cc150>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmgAAAJoCAYAAADS7x1JAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xl8XHW5+PFPkrakQGhRU7YLXPTCV6+KICgUZBEBqSAI\nKiAUKGsBWVQ2BYqXIkrLJqAgIKVlkRZRsAoVEJR6uXUBWQUfQFT6Q4EK3aiE0jS/P86JCZlJm6WZ\nOe183q/XvMg8M3PmmW9CzzPf5Xzr2trakCRJUnHUVzsBSZIkvZ0FmiRJUsFYoEmSJBWMBZokSV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uw7awoVncOqp\n11U7LUmSVIY9aDXib397BZgHtBdlR+QxSZJUNPag1Yg99vggcAVwSn77Th6TJElFY4FWI55++mVg\nHO1DnHB2HpMkSUVjgVYjGhoaehSTJEnVZ4FWIyZMGMNaa02gfauntdaayIQJY6qclSRJKsdFAjVi\n+PDhPPTQYZxxxgRWW20w48cf5iU2JEkqKAu0GjJ8+HCuvvpLbvUkSVLBOcQpSZJUMBZokiRJBWOB\nJkmSVDDOQashLS0tTJ06k6amRvbc86M0NjZWOyVJklSGBVqNaGlp4YADbmfWrMMBGDnyeqZN29ci\nTZKkAnKIs0ZMnTqTWbNGAV8BvsKsWXswderMaqclSZLKsAetRsyf/xpwLXBJHjmP+fM3rGJGkiSp\nO/ag1Yjp0x+m616cWUySJBWNPWg1or6+HmgB7skjO+QxSZJUNJ6ha8SVVx4JTAB2z28T85gkSSoa\nC7QacdFFdwFfp2OI85w8JklSefPmzWPs2G/zhS9cwLx586qdTk1xiFOSJJWYN28eW289hQULvgrA\nXXdN4KGHDmP48OFVzqw
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10e046810>"
|
||
|
]
|
||
|
},
|
||
|
"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",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {
|
||
|
"collapsed": false
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"<matplotlib.legend.Legend at 0x10c93f450>"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 12,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAf0AAAFtCAYAAAANqrPLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XecFdX5+PHPbdt7pZdd4NDFCjbEFqKJfk2iKfozif2L\nUZMYTTOaGKNGTbMnGqMxMfGrJjH2QjSoqCgoIAgH2KXD9t27ffeW+f0xd5Zl2XLLzMLuPu/Xy5fs\nnZkzZ3ZhnzntOS7DMBBCCCHE8Oc+2BUQQgghxOCQoC+EEEKMEBL0hRBCiBFCgr4QQggxQkjQF0II\nIUYICfpCCCHECOE92BUQIl5KKR+wHVijtT7DxnK/CdwNlEc+8gA1wA+01h/adZ9u97sCyNFa36GU\nuhTwaa0fjOH6MLAOCAEG4AOe0Fr/Uim1CLhXaz1ngDJuAlZrrZ/r8fki4EGt9YxYnqnb9ZOAMmBt\nt49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Orjvvt/xrW9dxlVXXc7113+bqqpKAM499ywCgaGz\ns7EEfSEOknBHBzX/eAZ3aire/Hz8y96kY/eug10tIYadJ574M3fe+YsBg/OqVR/yySdrDvj8nnt+\nTXHxKO6//2Huu+8hzjrrC9x0k7n78lDLCOtkch4hRD+aVn5AuLWFvM+dRfLESex94F4a311O4Xlf\nOdhVE8IRT72xhQ83Vtla5tHTi/jyKVP6PWfcuPHceutd3HLLTV2f/fOfT/PKKy/idruZPn0m11xz\nLX/962N0dHQwZ85hHH/8iQAEAgHeeectrr/+x13XLly4iHnzjtjvHuXlW7jvvt8RCoXx+xu47rof\nMnv2XG677WZ2795FR0c
|
||
|
"text/plain": [
|
||
|
"<matplotlib.figure.Figure at 0x10e0a96d0>"
|
||
|
]
|
||
|
},
|
||
|
"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
|
||
|
}
|