text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.model_selection import train_test_split

import pandas as pd

train = pd.read_csv('train.csv')

train.isnull().sum()

train_x = train[['Pclass', 'Sex']]

train_y = train[['Survived']]

train_x['Sex'].replace('male', 1, inplace=True)
train_x['Sex'].replace('female', 0, inplace=True)

tr_x, cv_x, tr_y, cv_y = train_test_split(train_x, train_y, test_size=0.3)

rf = RandomForestClassifier()

rf.fit(tr_x, tr_y)

Accuracy_RandomForest = rf.score(cv_x, cv_y)
print('Accuracy = {}%'.format(Accuracy_RandomForest * 100))