Kaggle competition: Titanic - Machine Learning from Disaster
def build_model() :
model = Sequential()
model.add(Dense(80,input_dim=X_train.shape[1],activation='relu'))
model.add(Dense(160,activation='relu'))
model.add(Dense(320,activation='relu'))
model.add(Dropout(0.1))
model.add(Dense(160,activation='relu'))
model.add(Dense(80,activation='relu'))
model.add(Dense(40,activation='relu'))
model.add(Dense(20,activation='relu'))
model.add(Dense(1,activation='sigmoid'))
model.compile(optimizer='adam', loss='mse', metrics=['mae'])
 return model<define_variables>
titanic_data = pd.read_csv('.. /input/titanic/train.csv')
 titanic_data.head()
k = 4
num_val_samples = len(X_train)// k 
<drop_column>
features = [x for x in titanic_data.columns if x not in ['Survived']]
X = titanic_data[features]
y = titanic_data['Survived']
K.clear_session()<define_variables>
X_initial = X.copy()
X_initial['family_size'] = X_initial['SibSp'] + X_initial['Parch'] + 1
X_initial['embarked_class'] = X_initial['Embarked'] + '_' + X_initial['Pclass'].astype(str)
 X_initial = X_initial.drop(columns=['Name', 'Cabin', 'Ticket'], axis=1)
 numerical_cols = [cname for cname in X_initial.columns if
X_initial[cname].dtype in ['int64', 'float64']]
categorical_cols = [cname for cname in X_initial.columns if
X_initial[cname].nunique() < 18 and
X_initial[cname].dtype in ['object', 'bool']]
numerical_transformer = SimpleImputer(strategy='constant')
 categorical_transformer = Pipeline(steps=[ 
('imputer', SimpleImputer(strategy='most_frequent')) , 
('onehot', OneHotEncoder(handle_unknown='ignore'))
])
 preprocessor = ColumnTransformer(
 transformers=[ 
('num', numerical_transformer, numerical_cols), 
('cat', categorical_transformer, categorical_cols)
 ])
 model = XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=1.0, gamma=1.5, gpu_id=-1,
importance_type='gain', interaction_constraints='',
learning_rate=0.02, max_delta_step=0, max_depth=6,
min_child_weight=1, monotone_constraints='() ',
n_estimators=400, n_jobs=1, nthread=1, num_parallel_tree=1,
random_state=0, reg_alpha=0, reg_lambda=1, scale_pos_weight=1,
subsample=1.0, tree_method='exact', validate_parameters=1,
verbosity=None)
 clf = Pipeline(steps=[('preprocessor', preprocessor), 
('model', model)
 ])
 X_train, X_valid, y_train, y_valid = train_test_split(X_initial, y, random_state=0)
 clf.fit(X_train, y_train)
 preds = clf.predict(X_valid)
 print('Accuracy Score:', accuracy_score(y_valid, preds))
<define_variables><EOS> 
X_test = pd.read_csv('.. /input/titanic/test.csv')
 X_test['family_size'] = X_test['SibSp'] + X_test['Parch'] + 1
X_test['embarked_class'] = X_initial['Embarked'] + '_' + X_test['Pclass'].astype(str)
 X_test = X_test.drop(columns=['Name', 'Cabin', 'Ticket'], axis=1)
 preds = clf.predict(X_test)
 output = pd.DataFrame({'PassengerId': X_test.PassengerId,
'Survived': preds})
 output.to_csv('submission.csv', index=False )