text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df_train = pd.read_csv('../input/train.csv')
df_test = pd.read_csv('../input/test.csv')

n_train = df_train.shape[0]
n_test = df_test.shape[0]
ratio = round(n_train / (n_train + n_test), 1)

df_train.sample(10)

df_titanic = df_train.drop(['Ticket', 'Cabin', 'Name'], axis=1)

df_titanic_na = df_titanic.dropna()

df_titanic_na.Sex = df_titanic.Sex.map({'female': 0, 'male': 1})
df_titanic_na.Embarked = df_titanic.Embarked.map({'C': 0, 'Q': 1, 'S': 2})

g = sns.distplot(df_titanic_na.Survived, color="red", hist_kws={"alpha": 0.3}, kde=None)
g.set_xticks([0,1])
g.autoscale()
g.set_xticklabels(["Dead", "Survived"])

corrmat = df_titanic_na[['Survived', 'Pclass', 'Sex', 'Age', 'SibSp', 'Parch',
       'Fare', 'Embarked']].corr()

f, ax = plt.subplots(figsize=(10, 7))
sns.heatmap(corrmat, vmax=.8, square=True)

survived = df_titanic_na.Survived == 1
died = df_titanic_na.Survived == 0

g = sns.distplot(df_titanic_na.Embarked, color='darkgreen', hist_kws={'alpha': 0.3}, kde=None)
g.set_xticklabels(['Cherbourg', '', 'Queenstown', '', 'Southampton'])