Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<categorify>
ss = StandardScaler()
def model(x,y):
x, testx, y, testy = train_test_split(x, y, test_size=0.1, random_state=4355)
 all_models = ['sgd','svc','knn','rf','dtc', 'lr', 'LDA', 'xgboost']
models = [sgd,SVC, knn,rf,dtc,LogisticRegression, LDA, xgboost ]
for i,j in zip(models,all_models):
try:
model = i(random_state=344,n_components=5)
 except:
try:
model = i(random_state=344)
 except:
model = i()
model.fit(x,y)
 trsc = model.score(x,y)
 sc = model.score(testx,testy)
 print(f'For {j} we have train score of {trsc} and test score of {sc}')
 def modelR(x,y):
x, testx, y, testy = train_test_split(x, y, test_size=0.1, random_state=4355)
 all_models = ['svr','rfr','dtr', 'lreg', 'xgboostR']
models = [SVR,rfr,dtr,LinearRegression, xgboostR ]
for i,j in zip(models,all_models):
try:
model = i(random_state=344,n_components=5)
 except:
try:
model = i(random_state=344)
 except:
model = i()
model.fit(x,y)
 trsc = model.score(x,y)
 sc = model.score(testx,testy)
 print(f'For {j} we have train score of {trsc} and test score of {sc}')
 def scaler(df):
df = df.apply(lambda x:(x-x.mean())/x.std())
 return df
def pca(xd,n):
pca = PCA(n_components=n)
 xd = pca.fit(xd ).transform(xd)
 print(pca.explained_variance_ratio_)
 return xd
def setfig(w=10,h=7):
return plt.figure(figsize=[w,h])
 def predS(model, test_data):
pred = model.predict(test_data)
 test_data = pd.read_csv('.. /input/titanic/test.csv')
 td = {'PassengerId':test_data.PassengerId, 'Survived':pred}
pd.DataFrame(td ).to_csv('Submission.csv',index=False )
df_train['Embarked'] = df_train['Embarked'].map({'C': 0, 'Q': 1, 'S': 2})
 df_test['Embarked'] = df_test['Embarked'].map({'C': 0, 'Q': 1, 'S': 2} )<categorify>
import matplotlib.pyplot as plt
import seaborn as sns
df_train['Sex'] = df_train['Sex'].map({'female': 0, 'male': 1})
 df_test['Sex'] = df_test['Sex'].map({'female': 0, 'male': 1} )<categorify>
odata = pd.read_csv('/kaggle/input/titanic/train.csv')
 test_data = pd.read_csv('.. /input/titanic/test.csv')
 odata.head(3 )
df_train = pd.get_dummies(df_train, columns=['Initial'], prefix='Initial')
 df_test = pd.get_dummies(df_test, columns=['Initial'], prefix='Initial' )<categorify>
odata.isna().sum()
df_train = pd.get_dummies(df_train, columns=['Embarked'], prefix='Embarked')
 df_test = pd.get_dummies(df_test, columns=['Embarked'], prefix='Embarked' )<drop_column>
test_data.isna().sum()
df_train.drop(['PassengerId', 'Name', 'SibSp', 'Parch', 'Ticket','Age'], axis=1, inplace=True)
 df_test.drop(['PassengerId', 'Name', 'SibSp', 'Parch', 'Ticket','Age'], axis=1, inplace=True )<prepare_x_and_y>
odata = odata.drop(['PassengerId','Ticket','Cabin'],axis=1)
 odata.isna().sum()
X_train = df_train.drop('Survived', axis=1 ).values
target_label = df_train['Survived'].values
X_test = df_test.values<split>
data = odata.copy()
X_tr, X_vld, y_tr, y_vld = train_test_split(X_train, target_label, test_size=0.3, random_state=2018 )<compute_train_metric>
import re
gaussian = GaussianNB()
gaussian.fit(X_tr, y_tr)
 prediction = gaussian.predict(X_vld)
 acc_gaussian = round(accuracy_score(prediction,y_vld)* 100, 2)
 print(acc_gaussian )<compute_train_metric>
data.Name.str.extract('(\w{1,8})\.' ).isna().sum()
logreg = LogisticRegression()
logreg.fit(X_tr, y_tr)
 prediction2 = logreg.predict(X_vld)
 acc_logreg = round(accuracy_score(prediction2,y_vld)* 100, 2)
 print(acc_logreg )<compute_train_metric>
data['suffix'] = data.Name.str.extract('(\w{1,8})\.')
 data.drop('Name', axis=1, inplace=True)
 data.head()
svc = SVC()
svc.fit(X_tr, y_tr)
 prediction3 = svc.predict(X_vld)
 acc_svc = round(accuracy_score(prediction3,y_vld)* 100, 2 )<compute_train_metric>
data.suffix = data.suffix.apply(lambda x: x if(x in ['Mr', 'Miss', 'Mrs', 'Master'])else 'rare' )
linear_svc = LinearSVC()
linear_svc.fit(X_tr, y_tr)
 prediction4 = svc.predict(X_vld)
 acc_linear_svc = round(accuracy_score(prediction4,y_vld)* 100, 2 )<compute_train_metric>
data.isna().sum()
perceptron = Perceptron()
perceptron.fit(X_tr, y_tr)
 prediction5 = perceptron.predict(X_vld)
 acc_perceptron = round(accuracy_score(prediction5,y_vld)* 100, 2 )<train_model>
import math
decisiontree = DecisionTreeClassifier(criterion='gini', max_depth=5)
 decisiontree.fit(X_tr, y_tr)
 prediction6 = decisiontree.predict(X_vld)
 acc_decisiontree = round(accuracy_score(prediction6,y_vld)* 100, 2)
<predict_on_test>
print(sorted(set(data.Fare.apply(math.ceil))))
rf = RandomForestClassifier()
rf.fit(X_tr, y_tr)
 prediction7 = rf.predict(X_vld)
 acc_rf = round(accuracy_score(prediction7,y_vld)* 100, 2 )<train_model>
data['grouped_fare'] = data.Fare.apply(faregrp )
knn = KNeighborsClassifier()
knn.fit(X_tr, y_tr)
 prediction8 = knn.predict(X_vld)
 acc_knn = round(accuracy_score(prediction8,y_vld)* 100, 2 )<predict_on_test>
narows = data[data.Age.isna() ]
narows
sgd = SGDClassifier()
sgd.fit(X_tr, y_tr)
 prediction9 = knn.predict(X_vld)
 acc_sgd = round(accuracy_score(prediction9,y_vld)* 100, 2)
<train_model>
tempdata = data.dropna()
x = tempdata[['Parch', 'SibSp', 'Pclass']]
y = tempdata.Age
modelR(x,y)
 agepred = rfr()
agepred.fit(x, y)
 predicted = agepred.predict(narows[['Parch', 'SibSp', 'Pclass']])
 data.Age.fillna(pd.Series(predicted, index=narows.index), inplace=True )
gbk = GradientBoostingClassifier()
gbk.fit(X_tr,y_tr)
 prediction10 = gbk.predict(X_vld)
 acc_gbk = round(accuracy_score(prediction10,y_vld)* 100, 2 )<train_model>
def agegrp(age):
if 0<= age <=10:
return 1
if 10< age <=18:
return 2
if 18< age <=25:
return 3
if 25< age <=35:
return 4
if 35< age <=47:
return 5
if 47< age <=60:
return 6
if 60< age <=70:
return 7
if 70< age <=80:
return 8
xg_boost = xgb.XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bytree=0.65, gamma=2, learning_rate=0.3, max_delta_step=1,
max_depth=4, min_child_weight=2, missing=None, n_estimators=280,
n_jobs=1, nthread=None, objective='binary:logistic', random_state=0,
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
silent=True, subsample=1)
 xg_boost.fit(X_tr, y_tr)
 prediction11 = gbk.predict(X_vld)
 acc_xg_boost = round(accuracy_score(prediction11,y_vld)* 100, 2 )<create_dataframe>
data['age_grp'] = data.Age.apply(agegrp )
models = pd.DataFrame({
'Model': ['Support Vector Machines', 'KNN', 'Logistic Regression',
'Random Forest', 'Naive Bayes', 'Perceptron', 'Linear SVC',
'Decision Tree', 'Stochastic Gradient Descent', 'Gradient Boosting Classifier', 'XGboost'],
'Score': [acc_svc, acc_knn, acc_logreg,
acc_rf, acc_gaussian, acc_perceptron,acc_linear_svc, acc_decisiontree,
acc_sgd, acc_gbk, acc_xg_boost]})
 models.sort_values(by='Score', ascending=False )<load_from_csv>
data.Age[data.Age<=18].count()
submission = pd.read_csv('.. /input/sample_submission.csv' )<predict_on_test>
data.Age[data.Survived==1][data.Age<=18].count()
prediction = linear_svc.predict(X_test)
 submission['Survived'] = prediction<save_to_csv>
data.Embarked.fillna(data.Embarked.mode() [0], inplace=True )
submission.to_csv('./submission7.csv', index=False )<import_modules>
data.Embarked.mode()
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
from sklearn.utils import shuffle
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import Perceptron
from sklearn import svm
from sklearn.ensemble import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import confusion_matrix
from sklearn.ensemble import VotingClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import cross_val_predict
from sklearn.model_selection import cross_validate
from sklearn.model_selection import GridSearchCV
from sklearn import svm, tree, linear_model, neighbors, naive_bayes, ensemble, discriminant_analysis, gaussian_process
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
from sklearn import feature_selection
from sklearn import model_selection
from sklearn import metrics
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
import seaborn as sns
from pandas.tools.plotting import scatter_matrix<load_from_csv>
data['total_family_size'] = data.SibSp+data.Parch
data.drop(['SibSp', 'Parch'], axis=1, inplace=True)
 data.corr()
train_df = pd.read_csv(".. /input/train.csv")
 test_df = pd.read_csv(".. /input/test.csv")
 data_df = train_df.append(test_df )<feature_engineering>
data['familysize-fare+age+pclass'] = data.total_family_size - data.Fare+data.Age+data.Pclass
data.drop('total_family_size', axis=1, inplace=True)
 data.corr()
data_df['Title'] = data_df['Name']
for name_string in data_df['Name']:
data_df['Title'] = data_df['Name'].str.extract('([A-Za-z]+)\.', expand=True)
<define_variables>
data['age_fare'] = data.Fare-data.Age
data['agegrp_fare'] = data.Fare*data.age_grp
data.corr()
mapping = {'Mlle': 'Miss', 'Major': 'Mr', 'Col': 'Mr', 'Sir': 'Mr', 'Don': 'Mr', 'Mme': 'Miss',
'Jonkheer': 'Mr', 'Lady': 'Mrs', 'Capt': 'Mr', 'Countess': 'Mrs', 'Ms': 'Miss', 'Dona': 'Mrs'}
data_df.replace({'Title': mapping}, inplace=True)
 titles = ['Dr', 'Master', 'Miss', 'Mr', 'Mrs', 'Rev']<feature_engineering>
data.isna().sum()
for title in titles:
age_to_impute = data_df.groupby('Title')['Age'].median() [titles.index(title)]
data_df.loc[(data_df['Age'].isnull())&(data_df['Title'] == title), 'Age'] = age_to_impute
train_df['Age'] = data_df['Age'][:891]
test_df['Age'] = data_df['Age'][891:]
data_df.drop('Title', axis = 1, inplace = True )<feature_engineering>
dict(list(zip(['Mr', 'Mrs', 'Miss', 'Master', 'rare'], [1,2,3,4,5])) )
data_df['Family_Size'] = data_df['Parch'] + data_df['SibSp']
train_df['Family_Size'] = data_df['Family_Size'][:891]
test_df['Family_Size'] = data_df['Family_Size'][891:]<feature_engineering>
data['suff+fare'] = data.suffix+data.Fare
data['suff+Pclass'] = data.suffix-data.Pclass
data['suff-fs-fare+age+cls'] = data.suffix-data['familysize-fare+age+pclass']
data['suff+age_fare'] = data.suffix+data.age_fare
data['suff+agegrp_fare'] = data.suffix+data.agegrp_fare
data.corr()
data_df['Last_Name'] = data_df['Name'].apply(lambda x: str.split(x, ",")[0])
 data_df['Fare'].fillna(data_df['Fare'].mean() , inplace=True)
 data_df['Fare'].fillna(data_df['Fare'].mean() , inplace=True )<groupby>
data.isnull().sum()
train_size = len(train_df)
 test_size = len(test_df)
 fare_df = data_df.loc[data_df['Family_Size']>1, ["Last_Name", "Fare", "Family_Size"]].iloc[:train_size]
fare_diff =(((fare_df.groupby(['Last_Name', 'Family_Size'] ).max()
- fare_df.groupby(['Last_Name', 'Family_Size'] ).min())!=0 ).sum() /train_size * 100)
 print(( "Percentage of families with different fares is: %.1f" %(fare_diff.values[0])) + '%')
<data_type_conversions>
data.isnull().sum()
train_temp_df = data_df.iloc[:train_size]
family_df_grpby = train_temp_df[train_temp_df['Family_Size']>1][
['Last_Name', 'Fare', 'Family_Size', 'Survived']].groupby(['Last_Name', 'Fare'])
 family_df = pd.DataFrame(data=family_df_grpby.size() , columns=['Size in train'])
 family_df['Survived total'] = family_df_grpby['Survived'].sum().astype(int)
 family_df['Family_Size'] = family_df_grpby['Family_Size'].mean().astype(int)
 print("Whole family survived: %.1f"
%(100*len(family_df[family_df['Size in train']==family_df['Survived total'] ])/len(family_df)) +'%')
 print("Whole family perished: %.1f"
%(100*len(family_df[family_df['Survived total'] == 0])/len(family_df)) +'%')
<feature_engineering>
data.Embarked = data.Embarked.map({'C':1,'S':2, 'Q':3} )
DEFAULT_SURVIVAL_VALUE = 0.5
data_df['Family_Survival'] = DEFAULT_SURVIVAL_VALUE
for grp, grp_df in data_df[['Survived','Name', 'Last_Name', 'Fare', 'Ticket', 'PassengerId',
'SibSp', 'Parch', 'Age', 'Cabin']].groupby(['Last_Name', 'Fare']):
if(len(grp_df)!= 1):
for ind, row in grp_df.iterrows() :
smax = grp_df.drop(ind)['Survived'].max()
smin = grp_df.drop(ind)['Survived'].min()
passID = row['PassengerId']
if(smax == 1.0):
data_df.loc[data_df['PassengerId'] == passID, 'Family_Survival'] = 1
elif(smin==0.0):
data_df.loc[data_df['PassengerId'] == passID, 'Family_Survival'] = 0
print("Number of passengers with family survival information:",
data_df.loc[data_df['Family_Survival']!=0.5].shape[0])
<train_model>
data['embarked_suffix'] = data.Embarked/data.suffix
data.corr()
for _, grp_df in data_df.groupby('Ticket'):
if(len(grp_df)!= 1):
for ind, row in grp_df.iterrows() :
if(row['Family_Survival'] == 0)|(row['Family_Survival']== 0.5):
smax = grp_df.drop(ind)['Survived'].max()
smin = grp_df.drop(ind)['Survived'].min()
passID = row['PassengerId']
if(smax == 1.0):
data_df.loc[data_df['PassengerId'] == passID, 'Family_Survival'] = 1
elif(smin==0.0):
data_df.loc[data_df['PassengerId'] == passID, 'Family_Survival'] = 0
print("Number of passenger with family/group survival information: "
+str(data_df[data_df['Family_Survival']!=0.5].shape[0]))
train_df['Family_Survival'] = data_df['Family_Survival'][:891]
test_df['Family_Survival'] = data_df['Family_Survival'][891:]<feature_engineering>
data['pclass-suff+age'] = data.Pclass-data['suff+age_fare']
data['pclass/suff'] = data.Pclass/data.suffix
data.corr()
data_df['FareBin'] = pd.qcut(data_df['Fare'], 5)
<categorify>
data.Sex = data.Sex.map({'male':0, 'female':1})
 data.corr()
label = LabelEncoder()
data_df['FareBin_Code'] = label.fit_transform(data_df['FareBin'] )<drop_column>
v0 = data.copy()
train_df['FareBin_Code'] = data_df['FareBin_Code'][:891]
test_df['FareBin_Code'] = data_df['FareBin_Code'][891:]
train_df.drop(['Fare'], 1, inplace=True)
 test_df.drop(['Fare'], 1, inplace=True )<categorify>
data = v0.copy()
data_df['AgeBin'] = pd.qcut(data_df['Age'], 4)
 label = LabelEncoder()
data_df['AgeBin_Code'] = label.fit_transform(data_df['AgeBin'])
 train_df['AgeBin_Code'] = data_df['AgeBin_Code'][:891]
test_df['AgeBin_Code'] = data_df['AgeBin_Code'][891:]
train_df.drop(['Age'], 1, inplace=True)
 test_df.drop(['Age'], 1, inplace=True )<drop_column>
v1 = data.copy()
train_df['Sex'].replace(['male','female'],[0,1],inplace=True)
 test_df['Sex'].replace(['male','female'],[0,1],inplace=True)
 train_df.drop(['Name', 'PassengerId', 'SibSp', 'Parch', 'Ticket', 'Cabin',
'Embarked'], axis = 1, inplace = True)
 test_df.drop(['Name','PassengerId', 'SibSp', 'Parch', 'Ticket', 'Cabin',
'Embarked'], axis = 1, inplace = True )<prepare_x_and_y>
alldata = data.copy()
x = alldata.drop('Survived', axis=1)
 x = x[sorted(x)]
y = alldata.Survived
X = train_df.drop('Survived', 1)
 y = train_df['Survived']
X_test = test_df.copy()<normalization>
trainx, testx, trainy, testy = train_test_split(x, y, test_size=0.1, random_state=4355)
 xgb = xgboost(n_estimators=8, max_depth=3, random_state=345)
 xgb.fit(trainx, trainy)
 print(xgb.score(trainx, trainy))
print(xgb.score(testx, testy))
impcol = x.columns[xgb.feature_importances_.astype(bool)]
x = x[impcol]
impx = x.copy()
impy = y.copy()
model(x,y)
 trainx, testx, trainy, testy = train_test_split(x, y, test_size=0.1, random_state=4355)
 xgb = xgboost(n_estimators=8, max_depth=3, random_state=345)
 xgb.fit(trainx, trainy)
 print(xgb.score(trainx, trainy))
print(xgb.score(testx, testy))
std_scaler = StandardScaler()
X = std_scaler.fit_transform(X)
 X_test = std_scaler.transform(X_test )<import_modules>
alldata1 = corrdata.copy()
x = alldata1.drop('Survived', axis=1)
 x = x[sorted(x)]
y = alldata.Survived
corx = x.copy()
cory = y.copy()
from sklearn.model_selection import GridSearchCV<define_search_space>
model(x, y )
<train_on_grid>
trainx, testx, trainy, testy = train_test_split(x, y, test_size=0.1, random_state=4355)
 xgb = xgboost(n_estimators=8, max_depth=3, random_state=345)
 xgb.fit(trainx, trainy)
 print(xgb.score(trainx, trainy))
print(xgb.score(testx, testy))
<choose_model_class>
cor_impcol = x.columns[xgb.feature_importances_.astype(bool)]
x = x[x.columns[xgb.feature_importances_.astype(bool)]]
cor_impcol
<init_hyperparams>
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Dropout
n_neighbors = [6,7,8,9,10,11,12,14,16,18,20,22]
algorithm = ['auto']
weights = ['uniform', 'distance']
leaf_size = list(range(1,50,5))
hyperparams = {'algorithm': algorithm, 'weights': weights, 'leaf_size': leaf_size,
'n_neighbors': n_neighbors}
gd=GridSearchCV(estimator = KNeighborsClassifier() , param_grid = hyperparams, verbose=True,
cv=10, scoring = "accuracy")
 gd.fit(X, y)
 print(gd.best_score_)
 print(gd.best_estimator_)
<predict_on_test>
trainx, testx, trainy, testy = train_test_split(corx[cor_impcol], cory, test_size=0.1, random_state=4355)
 inpshape = trainx.shape
inpshape
gd.best_estimator_.fit(X, y)
 y_pred = gd.best_estimator_.predict(X_test )<save_to_csv>
model = Sequential([
Dense(10, activation='relu', input_shape=inpshape),
Dense(13, activation='relu'),
Dropout(0.3),
Dense(17, activation='relu'),
Dropout(0.3),
Dense(13, activation='relu'),
Dense(10, activation='relu'),
Dropout(0.3),
Dense(1, activation='sigmoid'),
])
 model.summary()
model.compile(metrics=['accuracy'], loss=['binary_crossentropy'] )
submission = pd.read_csv(".. /input/sample_submission.csv")
 submission['Survived'] = y_pred
submission.to_csv(".. /working/submission0615_9.csv", index = False )<set_options>
history = model.fit(trainx, trainy, batch_size=32, epochs=40, validation_split=0.1 )
plt.style.use('seaborn')
 sns.set(font_scale=2.5)
 warnings.filterwarnings('ignore')
 %matplotlib inline<load_from_csv>
model.evaluate(testx, testy )
df_train = pd.read_csv('.. /input/train.csv')
 df_test = pd.read_csv('.. /input/test.csv')
 df_train.head() 
<feature_engineering>
import pandas as pd
import numpy as np
df_train['FamilySize'] = df_train['SibSp'] + df_train['Parch'] + 1
df_test['FamilySize'] = df_test['SibSp'] + df_test['Parch'] + 1<feature_engineering>
import pandas as pd
import numpy as np
df_test.loc[df_test.Fare.isnull() , 'Fare'] = df_test['Fare'].mean()
df_train['Fare'] = df_train['Fare'].map(lambda i: np.log(i)if i > 0 else 0)
 df_test['Fare'] = df_test['Fare'].map(lambda i: np.log(i)if i > 0 else 0 )<feature_engineering>
test_data = Test(pd.read_csv('.. /input/titanic/test.csv'))
test_data = test_data.get_data()
df_train['Fare_r'] = 0
df_train.loc[df_train['Fare'] < 2.065, 'Fare_r'] = 0
df_train.loc[(2.065 <= df_train['Fare'])&(df_train['Fare'] < 2.44), 'Fare_r'] = 1
df_train.loc[(2.44 <= df_train['Fare'])&(df_train['Fare'] < 3.18), 'Fare_r'] = 2
df_train.loc[(3.18 <= df_train['Fare'])&(df_train['Fare'] < 3.75), 'Fare_r'] = 3
df_train.loc[3.75 <= df_train['Fare'], 'Fare_r'] = 4<feature_engineering>
for i in impx.columns:
if i not in test_data.columns:
print(i)
df_test['Fare_r'] = 0
df_test.loc[df_test['Fare'] < 2.065, 'Fare_r'] = 0
df_test.loc[(2.065 <= df_test['Fare'])&(df_test['Fare'] < 2.44), 'Fare_r'] = 1
df_test.loc[(2.44 <= df_test['Fare'])&(df_test['Fare'] < 3.18), 'Fare_r'] = 2
df_test.loc[(3.18 <= df_test['Fare'])&(df_test['Fare'] < 3.75), 'Fare_r'] = 3
df_test.loc[3.75 <= df_test['Fare'], 'Fare_r'] = 4<feature_engineering>
for i in test_data.columns:
if i not in impx.columns:
print(i)
df_train['Initial']= df_train.Name.str.extract('([A-Za-z]+)\.')
 df_test['Initial']= df_test.Name.str.extract('([A-Za-z]+)\.' )<categorify>
test_data = test_data[sorted(test_data)]
df_train['Initial'].replace(['Mlle','Mme','Ms','Dr','Major','Lady','Countess','Jonkheer','Col','Rev','Capt','Sir','Don', 'Dona'],
['Miss','Miss','Miss','Mr','Mr','Mrs','Mrs','Other','Other','Other','Mr','Mr','Mr', 'Mr'],inplace=True)
 df_test['Initial'].replace(['Mlle','Mme','Ms','Dr','Major','Lady','Countess','Jonkheer','Col','Rev','Capt','Sir','Don', 'Dona'],
['Miss','Miss','Miss','Mr','Mr','Mrs','Mrs','Other','Other','Other','Mr','Mr','Mr', 'Mr'],inplace=True )<feature_engineering>
Fmodel = xgboost(n_estimators=8, max_depth=3, random_state=345)
 Fmodel.fit(impx, impy)
 print(Fmodel.score(impx, impy))
<data_type_conversions><EOS> 
predS(Fmodel, test_data[impx.columns])