application_vnd.jupyter.stderr_output_2.png text_plain_output_3.png text_plain_output_1.png
from sklearn import preprocessing

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

data_train = pd.read_csv('../input/train.csv')
data_test = pd.read_csv('../input/test.csv')

data1 = data_train.copy(deep=True)
data2 = data_test.copy(deep=True)
frame = [data1, data2]
lis = []
lis1 = []
print(data1.info())
print(data2.info())
for col in data1:
    if data1[col].isnull().any():
        lis.append(col)
for col in data2:
    if data2[col].isnull().any():
        lis1.append(col)
lis.remove('Cabin')
lis1.remove('Cabin')
data1['Age'].fillna(data1['Age'].median(), inplace=True)
data1['Embarked'].fillna(data1['Embarked'].mode()[0], inplace=True)
data2['Age'].fillna(data2['Age'].median(), inplace=True)
data1['Fare'].fillna(data1['Fare'].median(), inplace=True)
data2['Fare'].fillna(data2['Fare'].median(), inplace=True)
drop_val = ['PassengerId', 'Cabin', 'Ticket']
data1.drop(drop_val, axis=1, inplace=True)
for dataset in frame:
    dataset['FamilySize'] = dataset['SibSp'] + dataset['Parch'] + 1
    dataset['IsAlone'] = 1
    dataset['IsAlone'].loc[dataset['FamilySize'] > 1] = 0
label = preprocessing.LabelEncoder()
for d in frame:
    d['Sex'] = label.fit_transform(d['Sex'])
    d['Embarked'] = label.fit_transform(d['Embarked'])
tar = ['Survived']
x_label = ['Pclass', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked', 'FamilySize', 'IsAlone']
data1.drop(['Name'], axis=1, inplace=True)