Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<split>
plt.style.use('fivethirtyeight')
 warnings.filterwarnings('ignore')
 %matplotlib inline
oof_train_lgb = np.zeros(( X_train.shape[0]))
oof_test_lgb = np.zeros(( X_test.shape[0], n_splits))
qwk_scores = []
oof_coefficients_lgb = []
kf = StratifiedKFold(n_splits=5, shuffle=True, random_state=1337)
 for i,(f_ind, outf_ind)in enumerate(kf.split(X_train, y_train.values)) :
X_tr = X_train.loc[f_ind].copy()
X_val = X_train.loc[outf_ind].copy()
y_tr, y_val = y_train[f_ind], y_train[outf_ind]
print('
y_tr distribution: {}'.format(Counter(y_tr)))
 d_train = lgb.Dataset(X_tr, label=y_tr)
 d_valid = lgb.Dataset(X_val, label=y_val)
 watchlist = [d_train, d_valid]
print('training LGB:')
 model = lgb.train(params,
train_set=d_train,
num_boost_round=num_rounds,
valid_sets=watchlist,
verbose_eval=verbose_eval,
early_stopping_rounds=early_stop)
 val_pred = model.predict(X_val, num_iteration=model.best_iteration)
 optR = OptimizedRounder()
optR.fit(val_pred, y_val)
 coefficients = optR.coefficients()
oof_coefficients_lgb.append(coefficients)
 pred_val_y_k = optR.predict(val_pred, coefficients)
 print("Valid Counts = ", Counter(y_val))
print("Predicted Counts = ", Counter(pred_val_y_k))
print("Coefficients = ", coefficients)
 qwk = cohen_kappa_score(y_val, pred_val_y_k, weights='quadratic')
 qwk_scores.append(qwk)
 print("QWK = ", qwk)
 test_pred = model.predict(X_test, num_iteration=model.best_iteration)
 oof_train_lgb[outf_ind] = val_pred
oof_test_lgb[:, i] = test_pred
print('{} cv mean QWK score : {}, coeffs {}'.format('LGBM', np.mean(qwk_scores)
 ,np.mean(np.array(oof_coefficients_lgb), axis=0)) )<compute_train_metric>
train_dataset_raw = pd.read_csv('.. /input/train.csv')
 test_dataset = pd.read_csv('.. /input/test.csv')
 train_dataset = train_dataset_raw.copy(deep = True)
 data_cleaner = [train_dataset, test_dataset]
train_dataset_raw.describe(include = 'all' )
optR = OptimizedRounder()
mean_coeffs = np.mean(np.array(oof_coefficients_lgb), axis=0)
 valid_pred = optR.predict(oof_train_lgb, mean_coeffs)
 qwk = cohen_kappa_score(y_train.values, valid_pred, weights='quadratic')
 print("QWK = ", qwk )<define_variables>
print(train_dataset.isnull().sum())
 print('-'*10)
 print(test_dataset.isnull().sum() )
mean_coeff_m =(np.array(oof_coefficients_lgb)+ np.array(oof_coefficients)) / 2<compute_train_metric>
for dataset in data_cleaner:
dataset['Age'].fillna(dataset['Age'].median() , inplace = True)
 dataset['Embarked'].fillna(dataset['Embarked'].mode() [0], inplace = True)
 dataset['Fare'].fillna(dataset['Fare'].median() , inplace = True )
optR = OptimizedRounder()
mean_coeffs = np.mean(np.array(mean_coeff_m), axis=0)
 valid_pred = optR.predict(( oof_train_lgb + oof_train)/ 2, mean_coeffs)
 qwk = cohen_kappa_score(y_train.values, valid_pred, weights='quadratic')
 print("QWK = ", qwk )<predict_on_test>
for dataset in data_cleaner:
dataset['CabinBool'] =(dataset['Cabin'].notnull().astype('int'))
dataset['FamilySize'] = dataset ['SibSp'] + dataset['Parch'] + 1
dataset['IsAlone'] = 1
dataset['IsAlone'].loc[dataset['FamilySize'] > 1] = 0
dataset['Title'] = dataset['Name'].str.split(", ", expand=True)[1].str.split(".", expand=True)[0]
dataset['FareBin'] = pd.qcut(dataset['Fare'], 4)
 dataset['AgeBin'] = pd.cut(dataset['Age'].astype(int), 6 )
train_predictions = optR.predict(( oof_train_lgb + oof_train)/ 2, mean_coeffs ).astype(np.int8)
 print(f'train pred distribution: {Counter(train_predictions)}')
 test_predictions = optR.predict(( oof_test_lgb.mean(axis=1)+ oof_test.mean(axis=1)) / 2, mean_coeffs ).astype(np.int8)
 print(f'test pred distribution: {Counter(test_predictions)}' )<save_to_csv>
train_dataset.sample(10)
 print(train_dataset['Title'].value_counts() )
test = pd.read_csv('.. /input/petfinder-adoption-prediction/test/test.csv', usecols=['PetID'])
 submission = pd.DataFrame({'PetID': test['PetID'].values, 'AdoptionSpeed': test_predictions})
 submission.to_csv('submission.csv', index=False)
 submission.head()<import_modules>
stat_min = 10
title_names =(train_dataset['Title'].value_counts() < stat_min)
 train_dataset['Title'] = train_dataset['Title'].apply(lambda x: 'Misc' if title_names.loc[x] == True else x)
 print(train_dataset['Title'].value_counts())
 print("-"*10)
 title_namest =(test_dataset['Title'].value_counts() < stat_min)
 test_dataset['Title'] = test_dataset['Title'].apply(lambda x: 'Misc' if title_namest.loc[x] == True else x )
%matplotlib inline<define_search_model>
label = LabelEncoder()
for dataset in data_cleaner:
dataset['AgeBin_Code'] = label.fit_transform(dataset['AgeBin'])
 dataset['FareBin_Code'] = label.fit_transform(dataset['FareBin'])
 print(train_dataset.columns)
 test_dataset.columns
isascii = lambda s: len(s)== len(s.encode())
 tknzr = TweetTokenizer()
ps = PorterStemmer()
lc = LancasterStemmer()
sb = SnowballStemmer("english" )<import_modules>
features_col=['Pclass','Sex','Embarked','IsAlone','Title','AgeBin_Code','FamilySize','FareBin_Code','CabinBool']
train_ds = train_dataset[features_col]
test_ds = test_dataset[features_col]
train_label = train_dataset['Survived']
print(train_ds.columns)
 train_ds.head()
from torch import nn
import torch
from torch.nn import functional as F
from torchvision.models import resnet50, resnet34, densenet201, densenet121
from torch.optim.lr_scheduler import StepLR
from torch.autograd import Variable
from torch.utils.data import TensorDataset<compute_test_metric>
one_hot_encoded_training_predictors = pd.get_dummies(train_ds)
 one_hot_encoded_testing_predictors = pd.get_dummies(test_ds )
def confusion_matrix(rater_a, rater_b, min_rating=None, max_rating=None):

 assert(len(rater_a)== len(rater_b))
if min_rating is None:
min_rating = min(rater_a + rater_b)
 if max_rating is None:
max_rating = max(rater_a + rater_b)
 num_ratings = int(max_rating - min_rating + 1)
 conf_mat = [[0 for i in range(num_ratings)]
for j in range(num_ratings)]
for a, b in zip(rater_a, rater_b):
conf_mat[a - min_rating][b - min_rating] += 1
return conf_mat
def histogram(ratings, min_rating=None, max_rating=None):

 if min_rating is None:
min_rating = min(ratings)
 if max_rating is None:
max_rating = max(ratings)
 num_ratings = int(max_rating - min_rating + 1)
 hist_ratings = [0 for x in range(num_ratings)]
for r in ratings:
hist_ratings[r - min_rating] += 1
return hist_ratings
def quadratic_weighted_kappa(y, y_pred):
min_rating, max_rating =None, None
rater_a, rater_b = np.array(y, dtype=int), np.array(y_pred, dtype=int)
 assert(len(rater_a)== len(rater_b))
if min_rating is None:
min_rating = min(min(rater_a), min(rater_b))
if max_rating is None:
max_rating = max(max(rater_a), max(rater_b))
conf_mat = confusion_matrix(rater_a, rater_b, min_rating, max_rating)
 num_ratings = len(conf_mat)
 num_scored_items = float(len(rater_a))
hist_rater_a = histogram(rater_a, min_rating, max_rating)
 hist_rater_b = histogram(rater_b, min_rating, max_rating)
 numerator, denominator = 0.0, 0.0
for i in range(num_ratings):
for j in range(num_ratings):
expected_count =(hist_rater_a[i] * hist_rater_b[j] / num_scored_items)
 d = np.square(i - j)/ np.square(num_ratings - 1)
 numerator += d * conf_mat[i][j] / num_scored_items
denominator += d * expected_count / num_scored_items
return(1.0 - numerator / denominator)
 def val_kappa(preds, train_data):
labels = train_data.get_label()
preds = np.argmax(preds.reshape(( -1,5)) , axis=1)
 return 'qwk', quadratic_weighted_kappa(labels, preds), True
def val_kappa_reg(preds, train_data, cdf):
labels = train_data.get_label()
preds = getTestScore2(preds, cdf)
 return 'qwk', quadratic_weighted_kappa(labels, preds), True
def get_cdf(hist):
return np.cumsum(hist/np.sum(hist))
def getScore(pred, cdf, valid=False):
num = pred.shape[0]
output = np.asarray([4]*num, dtype=int)
 rank = pred.argsort()
output[rank[:int(num*cdf[0]-1)]] = 0
output[rank[int(num*cdf[0]):int(num*cdf[1]-1)]] = 1
output[rank[int(num*cdf[1]):int(num*cdf[2]-1)]] = 2
output[rank[int(num*cdf[2]):int(num*cdf[3]-1)]] = 3
if valid:
cutoff = [ pred[rank[int(num*cdf[i]-1)]] for i in range(4)]
return output, cutoff
return output
def getTestScore(pred, cutoff):
num = pred.shape[0]
output = np.asarray([4]*num, dtype=int)
 for i in range(num):
if pred[i] <= cutoff[0]:
output[i] = 0
elif pred[i] <= cutoff[1]:
output[i] = 1
elif pred[i] <= cutoff[2]:
output[i] = 2
elif pred[i] <= cutoff[3]:
output[i] = 3
return output
def getTestScore2(pred, cdf):
num = pred.shape[0]
rank = pred.argsort()
output = np.asarray([4]*num, dtype=int)
 output[rank[:int(num*cdf[0]-1)]] = 0
output[rank[int(num*cdf[0]):int(num*cdf[1]-1)]] = 1
output[rank[int(num*cdf[1]):int(num*cdf[2]-1)]] = 2
output[rank[int(num*cdf[2]):int(num*cdf[3]-1)]] = 3
return output
def rmse(actual, predicted):
return sqrt(mean_squared_error(actual, predicted))
isascii = lambda s: len(s)== len(s.encode())
 def custom_tokenizer(text):
init_doc = tknzr.tokenize(text)
 retval = []
for t in init_doc:
if isascii(t):
retval.append(t)
 else:
for w in t:
retval.append(w)
 return retval
def build_emb_matrix(word_dict, emb_dict):
embed_size = 300
nb_words = len(word_dict)+1000
nb_oov = 0
embedding_matrix = np.zeros(( nb_words, embed_size), dtype=np.float32)
 unknown_vector = np.zeros(( embed_size,), dtype=np.float32)- 1.
 for key in tqdm(word_dict):
word = key
embedding_vector = emb_dict.get(word)
 if embedding_vector is not None:
embedding_matrix[word_dict[key]] = embedding_vector
continue
word = key.lower()
embedding_vector = emb_dict.get(word)
 if embedding_vector is not None:
embedding_matrix[word_dict[key]] = embedding_vector
continue
word = key.upper()
embedding_vector = emb_dict.get(word)
 if embedding_vector is not None:
embedding_matrix[word_dict[key]] = embedding_vector
continue
word = key.capitalize()
embedding_vector = emb_dict.get(word)
 if embedding_vector is not None:
embedding_matrix[word_dict[key]] = embedding_vector
continue
word = ps.stem(key)
 embedding_vector = emb_dict.get(word)
 if embedding_vector is not None:
embedding_matrix[word_dict[key]] = embedding_vector
continue
word = lc.stem(key)
 embedding_vector = emb_dict.get(word)
 if embedding_vector is not None:
embedding_matrix[word_dict[key]] = embedding_vector
continue
word = sb.stem(key)
 embedding_vector = emb_dict.get(word)
 if embedding_vector is not None:
embedding_matrix[word_dict[key]] = embedding_vector
continue
nb_oov+=1
embedding_matrix[word_dict[key]] = unknown_vector
return embedding_matrix, nb_words, nb_oov
def _init_esim_weights(module):
if isinstance(module, nn.Linear):
nn.init.kaiming_normal_(module.weight.data)
 nn.init.constant_(module.bias.data, 0.0)
 elif isinstance(module, nn.LSTM)or isinstance(module, nn.GRU):
if isinstance(module, nn.LSTM):
hidden_size = module.bias_hh_l0.data.shape[0] // 4
else:
hidden_size = module.bias_hh_l0.data.shape[0] // 3
for name, param in module.named_parameters() :
if 'bias' in name:
nn.init.constant_(param, 0.0)
 elif '_ih_' in name:
nn.init.xavier_normal_(param)
 elif '_hh_' in name:
nn.init.orthogonal_(param)
 param.data[hidden_size:(2 * hidden_size)] = 1.0<train_on_grid>
corln_col=['Title_Miss','Sex_male']
one_hot_encoded_training_predictors = one_hot_encoded_training_predictors.drop(corln_col,axis=1)
 one_hot_encoded_testing_predictors = one_hot_encoded_testing_predictors.drop(corln_col,axis=1 )
class OptimizedRounder(object):
def __init__(self):
self.coef_ = 0
def _kappa_loss(self, coef, X, y):
preds = pd.cut(X, [-np.inf] + list(np.sort(coef)) + [np.inf], labels = [0, 1, 2, 3, 4])
 return -cohen_kappa_score(y, preds, weights='quadratic')
 def fit(self, X, y):
loss_partial = partial(self._kappa_loss, X = X, y = y)
 initial_coef = [0.5, 1.5, 2.5, 3.5]
self.coef_ = sp.optimize.minimize(loss_partial, initial_coef, method='nelder-mead')
 def predict(self, X, coef):
preds = pd.cut(X, [-np.inf] + list(np.sort(coef)) + [np.inf], labels = [0, 1, 2, 3, 4])
 return preds
def coefficients(self):
return self.coef_['x']<choose_model_class>
from sklearn.svm import SVC, LinearSVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import make_scorer, accuracy_score
from sklearn import svm
from sklearn import metrics
from sklearn.metrics import confusion_matrix
class ResnetModel(nn.Module):
def __init__(self, resnet_fun = resnet50, freeze_basenet = True):
super(ResnetModel, self ).__init__()
self.resnet = resnet_fun(pretrained=False)
 if freeze_basenet:
for p in self.resnet.parameters() :
p.requires_grad = False
def init_resnet(self, path):
state = torch.load(path)
 self.resnet.load_state_dict(state)
 def forward(self, x):
batch_size = x.shape[0]
x = x/255.0
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
x = torch.cat([ 
(x[:, [0]] - mean[0])/ std[0], 
(x[:, [1]] - mean[1])/ std[1], 
(x[:, [2]] - mean[2])/ std[2],
], 1)
 x = self.resnet.conv1(x)
 x = self.resnet.bn1(x)
 x = self.resnet.relu(x)
 x = self.resnet.maxpool(x)
 x = self.resnet.layer1(x)
 x = self.resnet.layer2(x)
 x = self.resnet.layer3(x)
 x = self.resnet.layer4(x)
 x = F.adaptive_avg_pool2d(x, output_size=1 ).view(batch_size, -1)
 return x
class DenseModel(nn.Module):
def __init__(self, dense_func = densenet201, freeze_basenet = True):
super(DenseModel, self ).__init__()
self.densenet = dense_func(pretrained=False)
 if freeze_basenet:
for p in self.densenet.parameters() :
p.requires_grad = False
def init_densenet(self, path):
state = torch.load(path)
 self.densenet.load_state_dict(state)
 def forward(self, x):
batch_size = x.shape[0]
x = x/255.0
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
x = torch.cat([ 
(x[:, [0]] - mean[0])/ std[0], 
(x[:, [1]] - mean[1])/ std[1], 
(x[:, [2]] - mean[2])/ std[2],
], 1)
 x = self.densenet.features(x)
 x = F.adaptive_avg_pool2d(F.relu(x,inplace=True), output_size=1 ).view(batch_size, -1)
 return x 
<load_from_csv>
train_X, test_X, train_y, test_y = train_test_split(one_hot_encoded_training_predictors, train_label, test_size=0.20)
labels_state = pd.read_csv('.. /input/petfinder-adoption-prediction/color_labels.csv')
 labels_color = pd.read_csv('.. /input/petfinder-adoption-prediction/state_labels.csv' )<load_from_csv>
svc_clf = SVC(kernel='rbf',C=1,gamma=0.1)
 svc_clf.fit(train_X, train_y)
 pred_svc = svc_clf.predict(test_X)
 acc_svc = accuracy_score(test_y, pred_svc)
 print(acc_svc )
train = pd.read_csv('.. /input/petfinder-adoption-prediction/train/train.csv')
 test = pd.read_csv('.. /input/petfinder-adoption-prediction/test/test.csv')
 sample_submission = pd.read_csv('.. /input/petfinder-adoption-prediction/test/sample_submission.csv')
 train_len = len(train)
 data_df = pd.concat([train, test], sort=False ).reset_index(drop=True)
 data_df['Breed_full'] = data_df['Breed1'].astype(str)+'_'+data_df['Breed2'].astype(str)
 data_df['Color_full'] = data_df['Color1'].astype(str)+'_'+data_df['Color2'].astype(str)+'_'+data_df['Color3'].astype(str)
 data_df['Breed_full'],_ = pd.factorize(data_df['Breed_full'])
 data_df['Color_full'],_ = pd.factorize(data_df['Color_full'])
 data_df['State'],_ = pd.factorize(data_df['State'])
 data_df['hard_interaction'] = data_df['Type'].astype(str)+data_df['Gender'].astype(str)+ \
data_df['Vaccinated'].astype(str)+'_'+ \
data_df['Dewormed'].astype(str)+'_'+data_df['Sterilized'].astype(str)
 data_df['hard_interaction'],_ = pd.factorize(data_df['hard_interaction'])
 data_df['MaturitySize'] = data_df['MaturitySize'].replace(0, np.nan)
 data_df['FurLength'] = data_df['FurLength'].replace(0, np.nan)
 data_df['Vaccinated'] = data_df['Vaccinated'].replace(3, np.nan)
 data_df['Vaccinated'] = data_df['Vaccinated'].replace(2, 0)
 data_df['Dewormed'] = data_df['Dewormed'].replace(3, np.nan)
 data_df['Dewormed'] = data_df['Dewormed'].replace(2, 0)
 data_df['Sterilized'] = data_df['Sterilized'].replace(3, np.nan)
 data_df['Sterilized'] = data_df['Sterilized'].replace(2, 0)
 data_df['Health'] = data_df['Health'].replace(0, np.nan)
 data_df['age_in_year'] =(data_df['Age']//12 ).astype(np.int8)
 data_df['avg_fee'] = data_df['Fee']/data_df['Quantity']
data_df['avg_photo'] = data_df['PhotoAmt']/data_df['Quantity']
pattern = re.compile(r"[0-9\.:!]")
 data_df['empty_name'] = data_df['Name'].isnull().astype(np.int8)
 data_df['Name'] =data_df['Name'].fillna('')
 data_df['name_len'] = data_df['Name'].apply(lambda x: len(x))
data_df['strange_name'] = data_df['Name'].apply(lambda x: len(pattern.findall(x)) >0 ).astype(np.int8 )<feature_engineering>
linsvc_clf = LinearSVC()
linsvc_clf.fit(train_X, train_y)
 pred_linsvc = linsvc_clf.predict(test_X)
 acc_linsvc = accuracy_score(test_y, pred_linsvc)
 print(acc_linsvc )
data_df['color_num'] = 1
data_df['color_num'] += data_df['Color2'].apply(lambda x: 1 if x!=0 else 0)
 data_df['color_num'] += data_df['Color3'].apply(lambda x: 1 if x!=0 else 0 )<load_from_csv>
logreg_clf = LogisticRegression()
logreg_clf.fit(train_X, train_y)
 pred_logreg = logreg_clf.predict(test_X)
 acc_logreg = accuracy_score(test_y, pred_logreg)
 print(acc_logreg )
labels_breed = pd.read_csv('.. /input/petfinder-adoption-prediction/breed_labels.csv')
 labels_breed.rename(index=str, columns={'BreedName':'Breed1Name'},inplace=True)
 labels_breed['Breed2Name'] = labels_breed['Breed1Name'].values<merge>
knn_clf = KNeighborsClassifier()
knn_clf.fit(train_X, train_y)
 pred_knn = knn_clf.predict(test_X)
 acc_knn = accuracy_score(test_y, pred_knn)
 print(acc_knn)
data_df = data_df.merge(labels_breed[['BreedID','Breed1Name']], left_on='Breed1', right_on='BreedID', how='left')
 data_df.drop('BreedID',axis=1,inplace=True)
 data_df = data_df.merge(labels_breed[['BreedID','Breed2Name']], left_on='Breed2', right_on='BreedID', how='left')
 data_df.drop('BreedID',axis=1,inplace=True)
 data_df['Breed2Name'].fillna('',inplace=True)
 data_df['BreedName_full'] = data_df['Breed1Name']+' '+data_df['Breed2Name']<data_type_conversions>
gnb_clf = GaussianNB()
gnb_clf.fit(train_X, train_y)
 pred_gnb = gnb_clf.predict(test_X)
 acc_gnb = accuracy_score(test_y, pred_gnb)
 print(acc_gnb )
data_df['breed_noname'] = data_df['BreedName_full'].isnull().astype(np.int8)
 data_df['BreedName_full'].fillna('',inplace=True)
 data_df['BreedName_full'] = data_df['BreedName_full'].str.lower()<data_type_conversions>
model_performance = pd.DataFrame({
'Model': ['Radial SVM', 'Linear SVM',
'Logistic Regression', 'K Nearest Neighbors', 'Gaussian Naive Bayes'],
'Accuracy': [acc_svc, acc_linsvc,
acc_logreg, acc_knn, acc_gnb]
})
 model_performance.sort_values(by='Accuracy', ascending=False )
data_df['breed_num'] = 1
data_df['breed_num'] += data_df['Breed2'].apply(lambda x: 1 if x!=0 else 0)
 data_df['breed_mixed'] = data_df['BreedName_full'].apply(lambda x: x.find('mixed')>=0 ).astype(np.int8)
 data_df['breed_Domestic'] = data_df['BreedName_full'].apply(lambda x: x.find('domestic')>=0 ).astype(np.int8)
 data_df['pure_breed'] =(( data_df['breed_num']==1)&(data_df['breed_mixed']==0)).astype(np.int8 )<data_type_conversions>
kfold = KFold(n_splits=10, random_state=22)
 xyz=[]
accuracy=[]
std=[]
classifiers=['Linear Svm','Radial Svm','Logistic Regression','KNN','Decision Tree','Naive Bayes','Random Forest']
models=[svm.SVC(kernel='linear',gamma='auto'),svm.SVC(kernel='rbf',gamma='auto'),LogisticRegression() ,KNeighborsClassifier(n_neighbors=9),DecisionTreeClassifier() ,GaussianNB() ,RandomForestClassifier(n_estimators=100)]
for i in models:
model = i
cv_result = cross_val_score(model, train_X, train_y, cv = kfold,scoring = "accuracy")
 cv_result=cv_result
xyz.append(cv_result.mean())
 std.append(cv_result.std())
 accuracy.append(cv_result)
 new_models_dataframe2=pd.DataFrame({'CV Mean':xyz,'Std':std},index=classifiers)
 new_models_dataframe2
<load_pretrained>
sub_clf = RandomForestClassifier(n_estimators=100)
 sub_clf.fit(one_hot_encoded_training_predictors, train_label)
 submission_predictions = sub_clf.predict(one_hot_encoded_testing_predictors )
<define_variables><EOS> 
submission = pd.DataFrame({
"PassengerId": test_dataset['PassengerId'],
"Survived": submission_predictions
})
 submission.to_csv("titanic.csv", index=False )