Kaggle competition: Titanic - Machine Learning from Disaster
NROWS = 12000000
test_df = pd.read_csv(TEST_PATH)
 train_df = pd.read_csv(TRAIN_PATH, usecols=cols,nrows = NROWS, dtype=traintypes )<load_from_csv>
test_data = pd.read_csv("/kaggle/input/titanic/test.csv")
 test_data.head()
<drop_column>
women = train_data.loc[train_data.Sex == "female"]["Survived"]
rate_women = sum(women)/len(women)
 print("% of women who survived:", rate_women )
train_df = train_df.dropna(how = 'any', axis = 'rows' )<drop_column>
men = train_data.loc[train_data.Sex == "male"]["Survived"]
rate_men = sum(men)/len(men)
 print("% of men who survived:", rate_men )
def clean_df(df):
return df[(df.fare_amount > 0)& 
(df.pickup_longitude > -80)&(df.pickup_longitude < -70)& 
(df.pickup_latitude > 35)&(df.pickup_latitude < 45)& 
(df.dropoff_longitude > -80)&(df.dropoff_longitude < -70)& 
(df.dropoff_latitude > 35)&(df.dropoff_latitude < 45)& 
(df.passenger_count > 0)&(df.passenger_count < 10)] 
<concatenate>
y = train_data["Survived"]
features = ["Sex", "Pclass", "SibSp", "Parch"]
X = train_data[features].values
X_test = test_data[features].values
labelEncoder_gender = LabelEncoder()
X[:,0] = labelEncoder_gender.fit_transform(X[:,0])
 X = np.vstack(X[:, :] ).astype(np.float)
 labelEncoder_gender_test = LabelEncoder()
X_test[:,0] = labelEncoder_gender_test.fit_transform(X_test[:,0])
 X_test = np.vstack(X_test[:, :] ).astype(np.float)
 model = RandomForestClassifier(n_estimators=300, 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('my_submission.csv', index=False)
 print("Your submission was successfully saved!" )