text_plain_output_1.png
from sklearn import preprocessing

import pandas

import re

TRAIN_PATH = '../input/train.csv'
TEST_PATH = '../input/test.csv'
train = pandas.read_csv(TRAIN_PATH)
test = pandas.read_csv(TEST_PATH)

train.isnull().any()

test.isnull().any()

def deriveTitles(s):
    title = re.search('(?:\\S )(?P<title>\\w*)', s).group('title')
    if title == 'Mr':
        return 'adult'
    elif title == 'Don':
        return 'gentry'
    elif title == 'Dona':
        return 'gentry'
    elif title == 'Miss':
        return 'miss'
    elif title == 'Col':
        return 'military'
    elif title == 'Rev':
        return 'other'
    elif title == 'Lady':
        return 'gentry'
    elif title == 'Master':
        return 'child'
    elif title == 'Mme':
        return 'adult'
    elif title == 'Captain':
        return 'military'
    elif title == 'Dr':
        return 'other'
    elif title == 'Mrs':
        return 'adult'
    elif title == 'Sir':
        return 'gentry'
    elif title == 'Jonkheer':
        return 'gentry'
    elif title == 'Mlle':
        return 'miss'
    elif title == 'Major':
        return 'military'
    elif title == 'Ms':
        return 'miss'
    elif title == 'the Countess':
        return 'gentry'
    else:
        return 'other'
train['title'] = train.Name.apply(deriveTitles)
test['title'] = test.Name.apply(deriveTitles)
le = preprocessing.LabelEncoder()
titles = ['adult', 'gentry', 'miss', 'military', 'other', 'child']
le.fit(titles)
train['encodedTitle'] = le.transform(train['title']).astype('int')
test['encodedTitle'] = le.transform(test['title']).astype('int')

train.Embarked.fillna(value='S', inplace=True)

combined = pandas.concat([train, test])
combined.ParChCategories = combined.Parch > 2

combined.boxplot(column='Age', by='Pclass')