text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

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

Y_train = pd.read_csv('../input/genderclassmodel.csv')
test = pd.read_csv('../input/test.csv')
train = pd.read_csv('../input/train.csv')

_train = train.copy()
Y_train = _train['Survived'].copy()
_train.drop(['Name', 'Ticket', 'Cabin', 'Survived'], axis=1, inplace=True)
_train.fillna('-1', inplace=True)
_train.replace('male', 1, inplace=True)
_train.replace('female', 2, inplace=True)
_train.replace('C', 1, inplace=True)
_train.replace('Q', 2, inplace=True)
_train.replace('S', 3, inplace=True)
_test = test.copy()
_test.drop(['Name', 'Ticket', 'Cabin'], axis=1, inplace=True)
_test.fillna('-1', inplace=True)
_test.replace('male', 1, inplace=True)
_test.replace('female', 2, inplace=True)
_test.replace('C', 1, inplace=True)
_test.replace('Q', 2, inplace=True)
_test.replace('S', 3, inplace=True)

passenger_survived = train[train.Survived == 1]['PassengerId'].copy()
passenger_died = train[train.Survived == 0]['PassengerId'].copy()

_train_survived = _train[_train.PassengerId.isin(passenger_survived)].drop('PassengerId', axis=1)

model = RandomForestClassifier()
model.fit(_train, Y_train)

predicted = test[['PassengerId']].copy()
predicted['Survived'] = model.predict(_test)
print(predicted.to_csv(index=False))