text_plain_output_1.png
import numpy as np

import pandas as pd

train_df = pd.read_csv('../input/titanic/train.csv')
test_df = pd.read_csv('../input/titanic/test.csv')

train_df.isnull().sum()

test_df.isnull().sum()

def train_preprocess(train_df):
    train_df = train_df.fillna(train_df.groupby('Survived').transform('mean'))
    train_df['Sex'] = pd.get_dummies(train_df['Sex'], drop_first=True)
    train_df['Embarked'] = pd.get_dummies(train_df['Embarked'], drop_first=True)
    X = np.asarray(train_df.drop(['Name', 'Survived', 'Cabin', 'Ticket'], axis=1))
    y = np.asarray(train_df['Survived'])
    return (X, y)

def test_preprocess(test_df):
    for i in test_df.columns:
        if test_df[i].isnull().sum() != 0:
            if test_df[i].dtype == 'int64' or test_df[i].dtype == 'float64':
                mean = test_df[str(i)].mean()
                test_df[str(i)].replace(np.nan, mean, inplace=True)
    test_df['Sex'] = pd.get_dummies(test_df['Sex'], drop_first=True)
    test_df['Embarked'] = pd.get_dummies(test_df['Embarked'], drop_first=True)
    test_df = test_df.drop(['Name', 'Cabin', 'Ticket'], axis=1)
    X = np.asarray(test_df)
    return X

submission_csv = pd.read_csv('./submission_gb.csv')
submission_csv