Kaggle competition: Titanic - Machine Learning from Disaster
test_raw.Utilities.value_counts()<count_values>
gender_submission_path = "/kaggle/input/titanic/gender_submission.csv"
train_path = "/kaggle/input/titanic/train.csv"
test_path = "/kaggle/input/titanic/test.csv"
gender_submission = pd.read_csv(gender_submission_path)
 train_data = pd.read_csv(train_path)
 test_data = pd.read_csv(test_path )
combine=combine.drop(['Utilities'],axis=1)
 combine.Exterior1st.value_counts()<count_values>
rate_cabin_Nan = 1-(train_data.Cabin.count() /len(train_data.Cabin))
print("% of NaN values: " ,rate_cabin_Nan )
combine['Exterior1st']=combine['Exterior1st'].fillna('Other')
 combine.Exterior1st.value_counts()<count_values>
combine = [train_data, test_data]
for dataset in combine:
dataset["Sex"] = dataset["Sex"].map({"female": 1, "male" : 0} ).astype(int)
 train_data.head()
combine['Exterior2nd']=combine['Exterior2nd'].fillna('Other')
 combine.Exterior2nd.value_counts()<count_values>
frequent_port = train_data.Embarked.dropna().mode() [0]
frequent_port
combine.MasVnrType.value_counts()<count_values>
for dataset in combine:
dataset["Embarked"] = dataset["Embarked"].map({"S" : 0, "C" : 1, "Q" : 2} ).astype(int)
 train_data.head()
combine['MasVnrType']=combine['MasVnrType'].fillna('None')
 combine.MasVnrType.value_counts()<feature_engineering>
y = train_data.Survived
features = ["Pclass", "Sex", "Age", "SibSp", "Parch", "Fare", "Embarked"]
X = train_data[features]
X_test = test_data[features]
combine['MasVnrArea']=combine['MasVnrArea'].fillna(0)
 combine.MasVnrArea.isnull().sum()<count_values>
model = RandomForestClassifier(n_estimators=100, max_depth=5, random_state=1)
 model.fit(imputed_X, y)
 predictions = model.predict(imputed_X_test)
 output = pd.DataFrame({'PassengerId': test_data.PassengerId, 'Survived': predictions})
 output.to_csv('my_submission.csv', index=False)
 print("Your submission was successfully saved!" )