Kaggle competition: Titanic - Machine Learning from Disaster
%%time
gbm = lgbtrain(X_train, y_train, X_valid, y_valid )<predict_on_test>
train_data = pd.read_csv("/kaggle/input/titanic/train.csv")
 train_data.head()
predictions = np.expm1(rf.predict(rf_test)) + np.expm1(regressor_.predict(rf_test.values)) + np.expm1(gbm.predict(rf_test.values))
predictions /= 3<feature_engineering>
test_data = pd.read_csv("/kaggle/input/titanic/test.csv")
 test_data.head()
submission['revenue'] = np.round(predictions )<save_to_csv>
women = train_data.loc[train_data.Sex == 'female']["Survived"]
rate_women = sum(women)/len(women)
 print("% of women who survived:", rate_women )
submission.to_csv('submission_ensemble.csv', index = False )<import_modules>
men = train_data.loc[train_data.Sex == 'male']["Survived"]
rate_men = sum(men)/len(men)
 print("% of men who survived:", rate_men )
FileLinks('.' )<set_options>
y = train_data["Survived"]
features = ["Pclass", "Sex", "SibSp", "Parch", "Age", "Embarked"]
X = pd.get_dummies(train_data[features])
 X_test = pd.get_dummies(test_data[features])
 X.Age.fillna(X.Age.mean() , inplace=True)
 X_test.Age.fillna(X_test.Age.mean() , inplace=True)
 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('my_submission.csv', index=False)
 print("Your submission was successfully saved!" )
%matplotlib inline
plt.style.use('ggplot')
 %matplotlib notebook
py.init_notebook_mode(connected=True)
 warnings.filterwarnings('ignore')
 pd.set_option('display.max_columns', 100)
 pd.set_option('display.max_rows', 100)
<load_from_csv>
%%time
train_new= pd.read_csv('.. /input/train-new/train_new.csv')
 test_new = pd.read_csv('.. /input/train-new/test_new.csv')
 sam_sub = pd.read_csv('.. /input/tmdb-box-office-prediction/sample_submission.csv')
 print("train dataset:", train_new.shape,"
","test dataset: ",test_new.shape,"
","sample_submission dataset:", sam_sub.shape )<categorify>
train_new_agg=train_new
test_new_agg=test_new
train_new_agg['dataset']='train'
test_new_agg['dataset']='test'
big_and_beautiful_data=train_new_agg.append(test_new_agg)
 del train_new_agg
del test_new_agg
numerical_cols_df =[c for c in big_and_beautiful_data.columns if big_and_beautiful_data[c].dtype in [np.float, np.int] and c not in ['revenue', 'id']]
categorical_cols_df = [c for c in big_and_beautiful_data.columns if big_and_beautiful_data[c].dtype in [np.object]]
big_and_beautiful_data_num=big_and_beautiful_data[numerical_cols_df].fillna(big_and_beautiful_data[numerical_cols_df].mean())
 big_and_beautiful_data= pd.concat([big_and_beautiful_data_num, big_and_beautiful_data[categorical_cols_df],big_and_beautiful_data[['revenue', 'id']]], axis=1)
<categorify>
<drop_column><EOS>