Kaggle competition: Titanic - Machine Learning from Disaster
target = 'ConvertedSalary'
col='Currency'
X_temp = pd.concat([X_train, y_train], axis=1)
 summary = X_temp.groupby([col])[target].mean()
enc_test = X_test[col].map(summary)
 enc_test = enc_test.rename(columns={'purpose': 'purpose_te'})
 skf = StratifiedKFold(n_splits=5, random_state=71, shuffle=True)
 enc_train = Series(np.zeros(len(X_train)) , index=X_train.index)
 for i,(train_ix, val_ix)in enumerate(( skf.split(X_train, y_train))):
X_train_, _ = X_temp.iloc[train_ix], y_train.iloc[train_ix]
X_val, _ = X_temp.iloc[val_ix], y_train.iloc[val_ix]
summary = X_train_.groupby([col])[target].mean()
enc_train.iloc[val_ix] = X_val[col].map(summary)
 X_train=pd.concat([X_train, enc_train], axis=1)
 X_test=pd.concat([X_test, enc_test], axis=1)
 X_train = X_train.rename(columns={0: 'Currency_te'})
 X_test = X_test.rename(columns={0: 'Currency_te'} )<categorify>
%matplotlib inline
py.init_notebook_mode(connected=True)
 warnings.filterwarnings('ignore' )
target = 'ConvertedSalary'
col='MilitaryUS'
X_temp = pd.concat([X_train, y_train], axis=1)
 summary = X_temp.groupby([col])[target].mean()
enc_test = X_test[col].map(summary)
 enc_test = enc_test.rename(columns={'purpose': 'purpose_te'})
 skf = StratifiedKFold(n_splits=5, random_state=71, shuffle=True)
 enc_train = Series(np.zeros(len(X_train)) , index=X_train.index)
 for i,(train_ix, val_ix)in enumerate(( skf.split(X_train, y_train))):
X_train_, _ = X_temp.iloc[train_ix], y_train.iloc[train_ix]
X_val, _ = X_temp.iloc[val_ix], y_train.iloc[val_ix]
summary = X_train_.groupby([col])[target].mean()
enc_train.iloc[val_ix] = X_val[col].map(summary)
 X_train=pd.concat([X_train, enc_train], axis=1)
 X_test=pd.concat([X_test, enc_test], axis=1)
 X_train = X_train.rename(columns={0: 'MilitaryUS_te'})
 X_test = X_test.rename(columns={0: 'MilitaryUS_te'} )<categorify>
from sklearn.model_selection import GridSearchCV, train_test_split
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
from xgboost import XGBClassifier
encoder =OrdinalEncoder(cols=cats)
 X_train[cats] = encoder.fit_transform(X_train[cats])
 X_test[cats] = encoder.transform(X_test[cats] )<train_model>
train_df = pd.read_csv('.. /input/titanic/train.csv')
 print(train_df.shape)
 train_df.head()
X_train.fillna(-9999,inplace=True)
 X_test.fillna(-9999,inplace=True )<train_model>
test_df = pd.read_csv('.. /input/titanic/test.csv')
 print(test_df.shape)
 test_df.head()
%%time
X_train,X_val,y_train,y_val=train_test_split(X_train,y_train,random_state=71)
 train_dataset=lgb.Dataset(X_train,y_train)
 valid_dataset=lgb.Dataset(X_val,y_val,reference=train_dataset)
 params={"objective":"regression",
"metric":"rmse"
}
model2=lgb_tuner.train(params,
train_set=train_dataset,
valid_sets=[valid_dataset],
num_boost_round=300,
early_stopping_rounds=50 
)
 y_pred_tuned = model2.predict(X_val)
 tuned_metric = mean_squared_error(y_val, y_pred_tuned)**0.5
print('tuned model metric: ', tuned_metric)
<predict_on_test>
df = [train_df, test_df]
y_pred2= np.expm1(model2.predict(X_test)) 
<load_from_csv>
for data in df:
data['Title'] = data['Name'].str.extract(r',(\w+)\.', expand=False)
 pd.crosstab(train_df['Title'], train_df['Sex'] ).transpose()
sample_submission = pd.read_csv(".. /input/exam-for-students20200129/sample_submission.csv", index_col=0)
 df_test = pd.read_csv(".. /input/exam-for-students20200129/test.csv")
 df_train = pd.read_csv(".. /input/exam-for-students20200129/train.csv")
 df_train['SalaryType_flg'] = df_train.SalaryType.isnull()
df_test['SalaryType_flg'] = df_test.SalaryType.isnull()
df_train['Country_flg'] = df_train.Country.isnull()
df_test['Country_flg'] = df_test.Country.isnull()
df_train['Employment_flg'] = df_train.Employment.isnull()
df_test['Employment_flg'] = df_test.Employment.isnull()
df_train['Currency_flg'] = df_train.Currency.isnull()
df_test['Currency_flg'] = df_test.Currency.isnull()
df_train['YearsCodingProf'] = df_train.YearsCodingProf.isnull()
df_test['YearsCodingProf'] = df_test.YearsCodingProf.isnull()
df_train['ConvertedSalary'] = df_train['ConvertedSalary'].apply(np.log1p)
 y_train=df_train.ConvertedSalary
X_train=df_train.drop(['ConvertedSalary'], axis=1)
 X_test=df_test
cats = []
for col in X_train.columns:
if X_train[col].dtype == 'object':
cats.append(col)
 print(col, X_train[col].nunique())
 encoder =OrdinalEncoder(cols=cats)
 X_train[cats] = encoder.fit_transform(X_train[cats])
 X_test[cats] = encoder.transform(X_test[cats])
 X_train.fillna(-9999,inplace=True)
 X_test.fillna(-9999,inplace=True)
<train_model>
for data in df:
data['Title'] = data['Title'].replace(['Lady', 'Countess','Capt', 'Col', 'Don', 'Dr', 'Major', 'Rev', 'Sir', 'Jonkheer', 'Dona'], 'Rare')
 data['Title'] = data['Title'].replace('Mlle', 'Miss')
 data['Title'] = data['Title'].replace('Ms', 'Miss')
 data['Title'] = data['Title'].replace('Mme', 'Mrs')
 train_df[['Title', 'Survived']].groupby(['Title'] ).mean()
labels = {'Mr':1, 'Mrs':2, 'Master':3, 'Miss':4, 'Rare':5}
test_df.replace({'Title':labels}, inplace = True)
 train_df.replace({'Title':labels}, inplace = True)
 train_df['Title'] = train_df['Title'].fillna(0)
 train_df['Title'] = train_df['Title'].astype(int )
%%time
X_train,X_val,y_train,y_val=train_test_split(X_train,y_train,random_state=71)
 train_dataset=lgb.Dataset(X_train,y_train)
 valid_dataset=lgb.Dataset(X_val,y_val,reference=train_dataset)
 params={"objective":"regression",
"metric":"rmse"
}
model3=lgb_tuner.train(params,
train_set=train_dataset,
valid_sets=[valid_dataset],
num_boost_round=300,
early_stopping_rounds=50 
)
 y_pred_tuned = model3.predict(X_val)
 tuned_metric = mean_squared_error(y_val, y_pred_tuned)**0.5
print('tuned model metric: ', tuned_metric)
<predict_on_test>
pd.DataFrame({'Train':train_df.isnull().sum() , 'Test':test_df.isnull().sum() } ).transpose()
y_pred3 = np.expm1(model3.predict(X_test))<define_variables>
print('Missing Values in Age column: ',177/len(train_df['Age'])*100)
 print('Missing Values in Cabin column: ',687/len(train_df['Cabin'])*100)
 print('Missing Values in Embarked column: ',2/len(train_df['Embarked'])*100 )
y_pred_x=0.5*y_pred2+0.5*y_pred3 
<save_to_csv>
train_df["Age"] = train_df["Age"].fillna(-0.5)
 test_df["Age"] = test_df["Age"].fillna(-0.5)
 bins = [-1, 0, 5, 12, 18, 24, 35, 60, np.inf]
labels = ['Unknown', 'Baby', 'Child', 'Teenager', 'Student', 'Young Adult', 'Adult', 'Senior']
train_df['AgeGroup'] = pd.cut(train_df["Age"], bins, labels = labels)
 test_df['AgeGroup'] = pd.cut(test_df["Age"], bins, labels = labels)
sample_submission = pd.read_csv(".. /input/exam-for-students20200129/sample_submission.csv", index_col=0)
 sample_submission.ConvertedSalary = y_pred_x
now = datetime.datetime.now()
filename = './output/log_' + now.strftime('%Y%m%d_%H%M%S')+ '.csv'
sample_submission.to_csv(now.strftime('%Y%m%d_%H%M%S')+ '_sample_submission.csv' )<load_from_csv>
mr_age = train_df[train_df["Title"] == 1]["AgeGroup"].mode()
miss_age = train_df[train_df["Title"] == 2]["AgeGroup"].mode()
mrs_age = train_df[train_df["Title"] == 3]["AgeGroup"].mode()
master_age = train_df[train_df["Title"] == 4]["AgeGroup"].mode()
rare_age = train_df[train_df["Title"] == 5]["AgeGroup"].mode()
age_title_mapping = {1: "Young Adult", 2: "Student", 3: "Adult", 4: "Baby", 5: "Adult"}
for x in range(len(train_df["AgeGroup"])) :
if train_df["AgeGroup"][x] == "Unknown":
train_df["AgeGroup"][x] = age_title_mapping[train_df["Title"][x]]
for x in range(len(test_df["AgeGroup"])) :
if test_df["AgeGroup"][x] == "Unknown":
test_df["AgeGroup"][x] = age_title_mapping[test_df["Title"][x]]
<set_options>
age_mapping = {'Baby': 1, 'Child': 2, 'Teenager': 3, 'Student': 4, 'Young Adult': 5, 'Adult': 6, 'Senior': 7}
train_df['AgeGroup'] = train_df['AgeGroup'].map(age_mapping ).astype(int)
 test_df['AgeGroup'] = test_df['AgeGroup'].map(age_mapping ).astype(int )
warnings.filterwarnings('ignore')
 plt.style.use('ggplot')
 %matplotlib inline 
<load_from_csv>
train_df['Embarked'].fillna('S', inplace = True)
 label = {'S':1, 'C':2, 'Q':3}
train_df.replace({'Embarked':label}, inplace = True)
 test_df.replace({'Embarked':label}, inplace = True )
df_train_original = pd.read_csv('.. /input/exam-for-students20200129/train.csv', index_col=0)
 df_test_original = pd.read_csv('.. /input/exam-for-students20200129/test.csv',index_col=0)
 target = 'ConvertedSalary'
df_country_original = pd.read_csv('.. /input/exam-for-students20200129/country_info.csv')
 df_train_original.shape, df_test_original.shape<create_dataframe>
train_df['Cabin'] = train_df['Cabin'].fillna('X')
 test_df['Cabin']=test_df['Cabin'].fillna('X' )
df_train = df_train_original.copy()
df_test = df_test_original.copy()
df_country = df_country_original.copy()
df_test_with_targetcol = df_test_original.copy()
df_test_with_targetcol[target] = -1
df_all = pd.concat([df_train, df_test_with_targetcol], axis=0 )<merge>
for data in df:
data['Cabin'] = data['Cabin'].map(lambda x: re.compile("([a-zA-Z]+)" ).search(x ).group())
 category = {'A':1, 'B':2, 'C':3, 'D':4, 'E':5, 'F':6, 'G':7, 'X':8, 'T':9}
for data in df:
data['Cabin'] = data['Cabin'].map(category )
df_GDP = df_country[['Country', 'GDP($ per capita)']]
df_train = df_train.merge(df_GDP, on = ['Country'], how = 'left')
 df_test = df_test.merge(df_GDP, on = ['Country'], how = 'left')
 df_all = df_all.merge(df_GDP, on = ['Country'], how = 'left' )<count_values>
train_df['Fare'] = pd.to_numeric(train_df['Fare'] )
c = 'Country'
df_train[c].value_counts()<count_values>
label = {'male':1, 'female':0}
train_df.replace({'Sex':label}, inplace = True)
 test_df.replace({'Sex':label}, inplace = True )
df_test[c].value_counts() 
<filter>
for data in df:
data['FamilySize'] = data['SibSp'] + data['Parch'] + 1
train_df[['FamilySize', 'Survived']].groupby(['FamilySize'], as_index=False ).mean().sort_values(by='Survived', ascending=False )
df_train[df_train['Country'] == 'Germany']
df_train[df_train['Country'] == 'France']<count_values>
for data in df:
data['IsAlone'] = 0
data.loc[data['FamilySize'] == 1, 'IsAlone'] = 1
train_df[['IsAlone', 'Survived']].groupby(['IsAlone'], as_index=False ).mean()
for col in df_all.columns:
print(df_all[col].value_counts())
 print('____')
<define_variables>
train_df.drop(['PassengerId', 'Name', 'Ticket', 'Age', 'SibSp', 'Parch', 'FamilySize'], axis = 1, inplace = True)
 test_df.drop(['Name', 'Ticket', 'Age', 'SibSp', 'Parch', 'FamilySize'], axis = 1, inplace = True )
first_log = True<concatenate>
X = train_df.drop('Survived', axis = 1)
 y = train_df['Survived']
y_train = df_train[target]
X_train = df_train.drop([target], axis=1)
 X_test = df_test
X_all = pd.concat([X_train, X_test], axis = 0)
 X_train = X_train[y_train.isnull() ==False]
y_train = y_train[y_train.isnull() ==False]
if(first_log == True):
y_train = y_train.apply(np.log1p )<create_dataframe>
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 123 )
TXT_train_DevType = X_train.DevType.copy()
TXT_test_DevType = X_test.DevType.copy()
TXT_train_CommunicationTools = X_train.CommunicationTools.copy()
TXT_test_CommunicationTools = X_test.CommunicationTools.copy()
TXT_train_FrameworkWorkedWith = X_train.FrameworkWorkedWith.copy()
TXT_test_FrameworkWorkedWith = X_test.FrameworkWorkedWith.copy()
TXT_train_DevType.fillna('
TXT_test_DevType.fillna('
TXT_train_CommunicationTools.fillna('
TXT_test_CommunicationTools.fillna('
TXT_train_FrameworkWorkedWith.fillna('
TXT_test_FrameworkWorkedWith.fillna('<feature_engineering>
from sklearn.metrics import accuracy_score
X_train['missing_sum'] = X_train.isnull().sum(axis=1)
 X_test['missing_sum'] = X_test.isnull().sum(axis=1 )<data_type_conversions>
lr = LogisticRegression()
lr.fit(X_train, y_train)
 y_pred = lr.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
lr_train_acc = round(lr.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', lr_train_acc)
 lr_test_acc = round(lr.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', lr_test_acc )
X_train['DevType'].fillna('
X_test['DevType'].fillna('
X_train['CommunicationTools'].fillna('
X_test['CommunicationTools'].fillna('
X_train['FrameworkWorkedWith'].fillna('
X_test['FrameworkWorkedWith'].fillna('<categorify>
knn = KNeighborsClassifier(n_neighbors = 3)
 knn.fit(X_train, y_train)
 y_pred = knn.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
knn_train_acc = round(knn.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', knn_train_acc)
 knn_test_acc = round(knn.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', knn_test_acc )
def mapping(map_col, mapping):
X_train[map_col]=X_train[map_col].map(mapping)
 X_test[map_col]=X_test[map_col].map(mapping )<define_variables>
svc = SVC()
param_grid = {'C': [0.01, 0.1, 1 ,10 , 100], 'kernel':['linear', 'rbf'], 'gamma':[0.1, 1, 10, 100]}
gcv = GridSearchCV(estimator = svc, param_grid = param_grid, cv = 5, n_jobs=-1, refit=True)
 gcv.fit(X_train, y_train)
 gcv.best_params_
Age_mapping = {'Under 18 years old':18, '18 - 24 years old':24, '25 - 34 years old':34, '35 - 44 years old':44,
'45 - 54 years old':54, '55 - 64 years old':64, '65 years or older':65}
CompanySize_mapping ={'Fewer than 10 employees':10, '10 to 19 employees':19,
'20 to 99 employees':99, '100 to 499 employees':499, '500 to 999 employees':999,
'1,000 to 4,999 employees':4999, '5,000 to 9,999 employees':9999,
'10,000 or more employees':20000}
Exercise_mapping = {'I don't typically exercise':0, '1 - 2 times per week':2,
'3 - 4 times per week':4, 'Daily or almost every day':7}
HoursComputer_mapping = {'Less than 1 hour':1, '1 - 4 hours':4, '5 - 8 hours':8, '9 - 12 hours':12, 'Over 12 hours':15}
HoursOutside_mapping = {'Less than 30 minutes':0.5, '30 - 59 minutes':1, '1 - 2 hours':2, '3 - 4 hours':4, 'Over 4 hours':6}
LastNewJob_mapping = {'I've never had a job':0, 'Less than a year ago':1, 'Between 1 and 2 years ago':2,
'Between 2 and 4 years ago':4, 'More than 4 years ago': 5}
SkipMeals_mapping = {'Never':0, '1 - 2 times per week':2, '3 - 4 times per week':4, 'Daily or almost every day':7}
StackOverflowJobsRecommend_mapping = {'0(Not Likely)':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9,
'10(Very Likely)':10}
YearsCoding_mapping ={'0-2 years':2, '3-5 years':5, '6-8 years': 8, '9-11 years':11, '12-14 years':14, '15-17 years':17,
'18-20 years':20, '21-23 years':23, '24-26 years':26,
'27-29 years':29, '30 or more years':25}
YearsCodingProf_mapping = YearsCoding_mapping<categorify>
svc = SVC(C = 10, gamma = 0.1, kernel = 'rbf')
 svc.fit(X_train,y_train)
 y_pred = svc.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
svc_train_acc = round(svc.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', svc_train_acc)
 svc_test_acc = round(svc.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', svc_test_acc )
mapping('Age', Age_mapping)
 mapping('CompanySize', CompanySize_mapping)
 mapping('Exercise', Exercise_mapping)
 mapping('HoursComputer', HoursComputer_mapping)
 mapping('HoursOutside', HoursOutside_mapping)
 mapping('LastNewJob', LastNewJob_mapping)
 mapping('SkipMeals', SkipMeals_mapping)
 mapping('StackOverflowJobsRecommend', StackOverflowJobsRecommend_mapping)
 mapping('YearsCoding', YearsCoding_mapping)
 mapping('YearsCodingProf', YearsCodingProf_mapping )<feature_engineering>
dt = DecisionTreeClassifier(max_depth = 6, min_samples_leaf = 2)
 dt.fit(X_train, y_train)
 y_pred = dt.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
dt_train_acc = round(dt.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', dt_train_acc)
 dt_test_acc = round(dt.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', dt_test_acc )
count_col = ['DevType', 'CommunicationTools', 'FrameworkWorkedWith']
for i in count_col:
X_train[i + '_count'] = X_train[i].apply(lambda x: len(re.split('\s*;\s*', x)))
 X_test[i + '_count'] = X_test[i].apply(lambda x: len(re.split('\s*;\s*', x)) )<feature_engineering>
rf = RandomForestClassifier()
param_grid = {'max_depth': [2, 4, 5, 6, 7, 8], 'criterion':['gini', 'entropy'], 'min_samples_leaf':[1, 2 ,4 ,6], 'max_features':['auto', 'log2'], 'n_estimators':[100,150,200]}
gcv = GridSearchCV(estimator=rf, param_grid=param_grid, cv = 5, n_jobs = -1)
 gcv.fit(X_train, y_train)
 gcv.best_params_
X_train['Github'] = X_train['CommunicationTools'].str.contains('Github')
 X_test['Github'] = X_test['CommunicationTools'].str.contains('Github')
 X_train['Full-stack'] = X_train['DevType'].str.contains('Full-stack')
 X_test['Full-stack'] = X_test['DevType'].str.contains('Full-stack')
 X_train['DataScientist'] = X_train['DevType'].str.contains('Data scientist')
 X_test['DataScientist'] = X_test['DevType'].str.contains('Data scientist' )<drop_column>
rf = RandomForestClassifier(max_depth = 8, min_samples_leaf = 6, n_estimators = 150)
 rf.fit(X_train, y_train)
 y_pred = rf.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
rf_train_acc = round(rf.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', rf_train_acc)
 rf_test_acc = round(rf.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', rf_test_acc )
del X_train['Country']
del X_test['Country']
del X_train['DevType']
del X_test['DevType']
del X_train['CommunicationTools']
del X_test['CommunicationTools']
del X_train['FrameworkWorkedWith']
del X_test['FrameworkWorkedWith']
del X_train['MilitaryUS']
del X_test['MilitaryUS']
del X_train['SurveyTooLong']
del X_test['SurveyTooLong']
del X_train['SurveyEasy']
del X_test['SurveyEasy']<data_type_conversions>
adb = AdaBoostClassifier(rf, n_estimators = 200)
 adb.fit(X_train, y_train)
 y_pred = adb.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
adb_train_acc = round(adb.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', adb_train_acc)
 adb_test_acc = round(adb.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', adb_test_acc )
X_train['AssessJob_null'] = X_train['AssessJob1'].isnull().astype(int)
 X_test['AssessJob_null'] = X_test['AssessJob1'].isnull().astype(int)
 X_train['AssessBenefits_null'] = X_train['AssessBenefits1'].isnull().astype(int)
 X_test['AssessBenefits_null'] = X_train['AssessBenefits1'].isnull().astype(int)
 X_train['JobContactPriorities_null'] = X_train['JobContactPriorities1'].isnull().astype(int)
 X_test['JobContactPriorities_null'] = X_test['JobContactPriorities1'].isnull().astype(int)
 X_train['JobEmailPriorities_null'] = X_train['JobEmailPriorities1'].isnull().astype(int)
 X_test['JobEmailPriorities_null'] = X_train['JobEmailPriorities1'].isnull().astype(int)
 X_train['questionaare_missing_count'] = X_train['AssessJob_null'] + X_train['AssessBenefits_null'] + X_train['JobContactPriorities_null'] + X_train['JobEmailPriorities_null']
X_test['questionaare_missing_count'] = X_test['AssessJob_null'] + X_test['AssessBenefits_null'] + X_test['JobContactPriorities_null'] + X_test['JobEmailPriorities_null']
del X_train['AssessJob_null']
del X_test['AssessJob_null']
del X_train['AssessBenefits_null']
del X_test['AssessBenefits_null']
del X_train['JobContactPriorities_null']
del X_test['JobContactPriorities_null']
del X_train['JobEmailPriorities_null']
del X_test['JobEmailPriorities_null']<categorify>
gdb = GradientBoostingClassifier()
params = {'learning_rate':[0.01,0.1,1,10],'n_estimators':[100,150,200,300],'subsample':[0.6,0.8,1.0],'max_depth':[2,3,4,6],'min_samples_leaf':[1,2,4,6]}
gcv = GridSearchCV(estimator=gdb, param_grid=params, cv=5, n_jobs=-1)
 gcv.fit(X_train, y_train)
 gcv.best_params_
col_yj_transform = ['GDP($ per capita)']
for col in col_yj_transform:
pt = PowerTransformer(method='yeo-johnson')
 reshape_train = X_train[col].values.reshape(-1,1)
 reshape_test = X_test[col].values.reshape(-1,1)
 pt.fit(reshape_train)
 X_train[col] = pt.transform(reshape_train)
 X_test[col] = pt.transform(reshape_test )<count_unique_values>
gdb = GradientBoostingClassifier(max_depth = 2, n_estimators = 300, subsample = 0.8)
 gdb.fit(X_train, y_train)
 y_pred = gdb.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
gdb_train_acc = round(gdb.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', gdb_train_acc)
 gdb_test_acc = round(gdb.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', gdb_test_acc )
cats = []
for col in X_train.columns:
if(X_train[col].dtype == 'object'):
cats.append(col)
 print(col, X_train[col].nunique() )<categorify>
xgbc = XGBClassifier(max_depth = 4)
 xgbc.fit(X_train, y_train)
 y_pred = xgbc.predict(X_test)
 print('Classification Report:
', classification_report(y_pred, y_test))
xgbc_train_acc = round(xgbc.score(X_train, y_train)* 100, 2)
 print('Training Accuracy: ', xgbc_train_acc)
 xgbc_test_acc = round(xgbc.score(X_test, y_test)* 100, 2)
 print('Testing Accuracy: ', xgbc_test_acc )
ordinal_col = cats
ordinal_encoder = OrdinalEncoder(cols = ordinal_col)
 X_train = ordinal_encoder.fit_transform(X_train)
 X_test = ordinal_encoder.transform(X_test )<train_model>
test_df['Fare'] = pd.to_numeric(test_df['Fare'] )
X_train.fillna(-9999, inplace = True)
 X_test.fillna(-9999, inplace = True )<count_values>
test_df['Survived'] = rf.predict(test_df.drop(['PassengerId'], axis = 1))
test_df[['PassengerId', 'Survived']].to_csv('MySubmission.csv', index = False )