text_html_output_1.png
from sklearn import preprocessing

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data = pd.read_csv('../input/train.csv')
test_data = pd.read_csv('../input/test.csv')

fig = plt.figure(figsize = (30,20))
ax = fig.gca()
hist = data.hist(ax=ax)

data['Sex'] = data['Sex'].map({'female': 1, 'male': 0})
data['Age'].fillna(data['Age'].mean(), inplace=True)
data['Embarked'].fillna(method='ffill', inplace=True)
one_hot_columns = pd.get_dummies(data['Embarked'], prefix=None)
data = pd.concat([data, one_hot_columns], axis=1)
data.drop(['Embarked'], axis=1, inplace=True)
import re
def ticket_to_float(ticket_str):
    ticket_numbers_only = ''.join((i for i in ticket_str if i.isdigit()))
    if ticket_numbers_only is '':
        return 0
    return int(ticket_numbers_only)
data['Ticket'] = data['Ticket'].apply(ticket_to_float)
test_data['Sex'] = test_data['Sex'].map({'female': 1, 'male': 0})
test_data['Age'].fillna(test_data['Age'].mean(), inplace=True)
test_data['Fare'].fillna(test_data['Fare'].mean(), inplace=True)
test_data['Embarked'].fillna(method='ffill', inplace=True)
one_hot_columns = pd.get_dummies(test_data['Embarked'], prefix=None)
test_data = pd.concat([test_data, one_hot_columns], axis=1)
test_data.drop(['Embarked'], axis=1, inplace=True)
test_data['Ticket'] = test_data['Ticket'].apply(ticket_to_float)

feature_columns = ['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'C', 'Q', 'S']

from sklearn import preprocessing

#Training Data
x = data[feature_columns].values 
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
data[feature_columns] = pd.DataFrame(x_scaled)

#Submission Data
# x = test_data[feature_columns].values 
# min_max_scaler = preprocessing.MinMaxScaler()
# x_scaled = min_max_scaler.fit_transform(x)
# test_data[feature_columns] = pd.DataFrame(x_scaled)

fig = plt.figure(figsize = (30,20))
ax = fig.gca()
hist = test_data[feature_columns].hist(ax=ax)

f = plt.figure(figsize=(19, 15))
plt.matshow(data[feature_columns].corr(), fignum=f.number)
plt.xticks(range(data[feature_columns].shape[1]), data[feature_columns].columns, fontsize=14, rotation=45)
plt.yticks(range(data[feature_columns].shape[1]), data[feature_columns].columns, fontsize=14)
cb = plt.colorbar()
cb.ax.tick_params(labelsize=14)
plt.title('Correlation Matrix', fontsize=16)