Kaggle competition: Titanic - Machine Learning from Disaster
train_file, test_file = 'train_28k.csv', 'test_5k.csv'<load_from_csv>
X_full = pd.read_csv('.. /input/titanic/train.csv', index_col='PassengerId')
 X_test_full = pd.read_csv('.. /input/titanic/test.csv', index_col='PassengerId')
 print(X_full.columns)
 y = X_full.Survived
features = ['Pclass', 'Sex', 'Age', 'SibSp', 'Parch','Fare', 'Cabin', 'Embarked']
X = X_full[features].copy()
X_test = X_test_full[features].copy()
X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size=0.8, test_size=0.2,
random_state=0 )
data_clas = TextClasDataBunch.from_csv(path=folder,
csv_name=train_file,
test=test_file,
vocab=data_lm.train_ds.vocab,
bs=64,
text_cols='text',
label_cols='label' )<save_model>
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)
 ])
 X_train = preprocessor.fit_transform(X_train)
 X_valid = preprocessor.transform(X_valid,)
 X_test = preprocessor.transform(X_test,)
data_clas.save('ulmfit_data_clas_clickbait_news' )<load_pretrained>
dtrain = xgb.DMatrix(X_train, label=y_train)
 dvalid = xgb.DMatrix(X_valid, label=y_valid)
 dtest = xgb.DMatrix(X_test)
 watchlist = [(dtrain, 'train'),(dvalid, 'valid')]
param = {'min_child_weight': 100, 'eta': 0.04, 'colsample_bytree': 0.8, 'max_depth': 100,
'subsample': 0.75, 'lambda': 2, 'nthread': -1, 'booster' : 'gbtree', 'silent': 1, 'gamma' : 0,
'eval_metric': 'rmse', 'objective': 'reg:linear'}
model = xgb.train(param, dtrain, 500, watchlist, early_stopping_rounds=250,
maximize=False, verbose_eval=15)
 preds = model.predict(dtest)
learn_clas = text_classifier_learner(data_clas, drop_mult=0.3, arch=AWD_LSTM)
 learn_clas.load_encoder('clickbait_news_enc' )<find_best_params>
test_predict = np.where(preds > 0.5, 1, 0)
 test_predict = pd.DataFrame({"PassengerId":X_test_full.index,"Survived":test_predict})
 test_predict.to_csv("submission.csv",index=False)