Kaggle competition: Titanic - Machine Learning from Disaster
wb_name.fit(X_train['name'])
 X_name_train_wb = wb_name.transform(X_train['name'])
 X_name_cv_wb = wb_name.fit_transform(X_cv['name'] )<define_variables>
data_set = pd.read_csv("/kaggle/input/titanic/train.csv")
 data_set_test = pd.read_csv("/kaggle/input/titanic/test.csv" )
mask_name = np.where(X_name_train_wb.getnnz(axis=0)> 3)[0]<split>
data_set['Embarked'] = data_set['Embarked'].fillna("S")
 data_set_test['Embarked'] = data_set_test['Embarked'].fillna("S" )
X_name_train_wb = X_name_train_wb[:, mask_name]
X_name_cv_wb = X_name_cv_wb[:, mask_name]<train_model>
X_train = data_set.iloc[:,[2, 4, 5, 6, 7, 9, 11]].values
Y_train = data_set.iloc[:,1].values
X_test = data_set_test.iloc[:,[1, 3, 4, 5, 6, 8, 10]].values
pid_col = data_set_test.iloc[:, 0].values
model_name = Ridge(solver="sag", fit_intercept=True, random_state=205, alpha= 5)
 model_name.fit(X_name_train_wb, Y_train)
<predict_on_test>
labelencoder_X = LabelEncoder()
X_train[:, 1] = labelencoder_X.fit_transform(X_train[:, 1])
 X_train[:, 6] = labelencoder_X.fit_transform(X_train[:, 6])
 X_test[:, 1] = labelencoder_X.fit_transform(X_test[:, 1])
 X_test[:, 6] = labelencoder_X.fit_transform(X_test[:, 6] )
pred_train_2 = model_name.predict(X_name_train_wb)
 pred_cv_2 = model_name.predict(X_name_cv_wb )<compute_test_metric>
imp = Imputer(missing_values='NaN', strategy='mean', axis=0)
 X_train[:,:] = imp.fit_transform(X_train[:,:])
 X_test[:,:] = imp.fit_transform(X_test[:,:] )
print("Train rmsle: "+str(rmsle(10 ** Y_train-1, 10 ** pred_train_2-1)))
 print("CV rmsle: "+str(rmsle(10 ** Y_cv-1, 10 ** pred_cv_2-1)) )<load_pretrained>
onehotencoder = OneHotEncoder(categorical_features = [6])
 X_train = onehotencoder.fit_transform(X_train ).toarray()
onehotencoder2 = OneHotEncoder(categorical_features = [6])
 X_test = onehotencoder2.fit_transform(X_test ).toarray()
pickle.dump(mask_name, open("mask_name.pickle", "wb"),protocol=4)
 pickle.dump(wb_name, open("wb_name.pickle", "wb"),protocol=4)
 pickle.dump(model_name, open("model_name.pickle", "wb"),protocol=4)
<drop_column>
classifier = XGBClassifier(learning_rate=0.001,n_estimators=1000)
 classifier.fit(X_train, Y_train )
mask_name = None
wb_name = None
model_name = None
del(mask_name,wb_name,model_name)
 gc.collect()<categorify>
Y_pred = classifier.predict(X_test )
<categorify><EOS> 
ans =pd.DataFrame({'PassengerId':pid_col, 'Survived':Y_pred})
 ans.to_csv("titanicPred.csv", index=False )