application_vnd.jupyter.stderr_output_2.png application_vnd.jupyter.stderr_output_1.png
import numpy as np

import pandas as pd

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from collections import Counter
import string
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import LabelEncoder
from sklearn.linear_model import LinearRegression
pd.options.mode.chained_assignment = None
def get_title(name):
    name = name.split(',')[1]
    name = name.split('.')[0]
    return name.strip()
def get_title_grouped(name):
    title = get_title(name)
    if title in ['Rev', 'Dr', 'Col', 'Major', 'the Countess', 'Sir', 'Lady', 'Jonkheer', 'Capt', 'Dona', 'Don']:
        title = 'Rare'
    elif title in ['Ms', 'Mlle']:
        title = 'Miss'
    elif title == 'Mme':
        title = 'Mrs'
    return title
def get_deck(cabin):
    if isinstance(cabin, str):
        if cabin[0] == 'T':
            return np.nan
        return cabin[0]
    return cabin
train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')
full = pd.concat([train, test])
full['Embarked'].fillna('C', inplace=True)
full['Fare'].fillna(8.05, inplace=True)
full['Title'] = full['Name'].apply(get_title_grouped)
full['Deck'] = full['Cabin'].apply(get_deck)
full['Family size'] = full['Parch'] + full['SibSp']