text_html_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.ensemble import RandomForestClassifier

import pandas as pd

train_data = pd.read_csv('/kaggle/input/titanic/train.csv')
test_data = pd.read_csv('/kaggle/input/titanic/test.csv')
gender = pd.read_csv('/kaggle/input/titanic/gender_submission.csv')

women = train_data.loc[train_data.Sex == 'female']['Survived']
rate_women = sum(women) / len(women)

men = train_data.loc[train_data.Sex == 'male']['Survived']
rate_men = sum(men) / len(women)

from sklearn.ensemble import RandomForestClassifier
y = train_data['Survived']
features = ['Pclass', 'Sex', 'SibSp', 'Parch']
X = pd.get_dummies(train_data[features])
X_test = pd.get_dummies(test_data[features])
model = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=1)
model.fit(X, y)
predictions = model.predict(X_test)
output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})
output.to_csv('submission.csv', index=False)
print('Your submission was successfully saved!')