Kaggle competition: Titanic - Machine Learning from Disaster
scenario_3 = train_df.loc[(train_df['S_Distance']!=0)&(train_df['fare_amount']==0)]
scenario_3<filter>
titanic=pd.read_csv('/kaggle/input/titanic/train.csv')
 titanic.head()
scenario_3 = train_df.loc[(train_df['S_Distance']!=0)&(train_df['fare_amount']==0)]<feature_engineering>
titanic_dummies=pd.get_dummies(data=titanic,columns=['Sex','Embarked'],drop_first=True)
 titanic_dummies.info()
scenario_3['fare_amount'] = scenario_3.apply(
 lambda row:(( row['S_Distance'] * 1.56)+ 2.50), axis=1
)<filter>
X=titanic_dummies.loc[:,['Sex_male','SibSp','Parch','Pclass','Fare','Embarked_S','Embarked_Q','Age','Fare']]
y=titanic_dummies['Survived']
X
train_df.loc[(train_df['S_Distance']==0)&(train_df['fare_amount']!=0)]<filter>
dt=RandomForestClassifier()
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=42)
 dt.fit(X_train,y_train )
scenario_4 = train_df.loc[(train_df['S_Distance']==0)&(train_df['fare_amount']!=0)]<filter>
dt.score(X_test,y_test)
 y_pred=dt.predict(X_test )
scenario_4.loc[(scenario_4['fare_amount']<=3.0)&(scenario_4['S_Distance']==0)]<filter>
confusion_matrix(y_test,y_pred )
scenario_4.loc[(scenario_4['fare_amount']>3.0)&(scenario_4['S_Distance']==0)]<filter>
test=pd.read_csv('/kaggle/input/titanic/test.csv')
 test_dummies=pd.get_dummies(data=test,columns=['Sex','Embarked'],drop_first=True)
 test_dummies['Fare'].fillna(test_dummies['Fare'].dropna().median() ,inplace=True)
 test_dummies['Age'].fillna(test_dummies['Age'].dropna().median() ,inplace=True)
 test_dummies.info()
scenario_4_sub = scenario_4.loc[(scenario_4['fare_amount']>3.0)&(scenario_4['S_Distance']==0)]<feature_engineering>
X_testf=test_dummies.loc[:,['Sex_male','SibSp','Parch','Pclass','Fare','Embarked_S','Embarked_Q','Age','Fare']]
predictions=dt.predict(X_testf )
scenario_4_sub['S_Distance'] = scenario_4_sub.apply(
 lambda row:(( row['fare_amount']-2.50)/1.56), axis=1
)<drop_column>
Id=test_dummies['PassengerId']
sub_df=pd.DataFrame({'PassengerId':Id,'Survived':predictions})
 sub_df.head()
train_df = train_df.drop(['key','pickup_datetime'], axis = 1)
 test_df = test_df.drop(['key','pickup_datetime'], axis = 1 )<prepare_x_and_y>
sub_df.to_csv('submission.csv',index=False )