Kaggle competition: Titanic - Machine Learning from Disaster
<SOS> metric: categorizationaccuracy Kaggle data source: titanic-machine-learning-from-disaster<define_variables>
import numpy as np
import pandas as pd
for i in range(EM_LEN):
emi = em_tasks[i]
aaa = 777
contains_train = len(emi['train'])
 contains_test = len(emi['test'])
 print(f'i = {i} >>> task contains {contains_train} training pairs')
 print(f'i = {i} >>> task contains {contains_test} test pairs')
 train_input0 = np.array(emi['train'][0]['input'])
 train_input0_fllr = np.fliplr(train_input0)
 train_input0_flud = np.flipud(train_input0)
 train_input0_r180 = np.rot90(train_input0, 2)
 train_input0_r270 = np.rot90(train_input0, 3)
 train_input0_r90 = np.rot90(train_input0, 1)
 flattrainin0 = train_input0.flatten()
flattrainin0_fllr = train_input0_fllr.flatten()
flattrainin0_flud = train_input0_flud.flatten()
flattrainin0_r180 = train_input0_r180.flatten()
flattrainin0_r270 = train_input0_r270.flatten()
flattrainin0_r90 = train_input0_r90.flatten()
flattraininx = flattrainin0
flattraininxx =np.hstack(( flattrainin0, flattrainin0_fllr, flattrainin0_flud, flattrainin0_r180))
flattrainin = np.hstack(( flattrainin0, flattrainin0_fllr, flattrainin0_flud, flattrainin0_r180,
flattrainin0_r270, flattrainin0_r90))
train_output0 = np.array(emi['train'][0]['output'])
 train_output0_fllr = np.fliplr(train_output0)
 train_output0_flud = np.flipud(train_output0)
 train_output0_r180 = np.rot90(train_output0, 2)
 train_output0_r270 = np.rot90(train_output0, 3)
 train_output0_r90 = np.rot90(train_output0, 1)
 flattrainout0 = train_output0.flatten()
flattrainout0_fllr = train_output0_fllr.flatten()
flattrainout0_flud = train_output0_flud.flatten()
flattrainout0_r180 = train_output0_r180.flatten()
flattrainout0_r270 = train_output0_r270.flatten()
flattrainout0_r90 = train_output0_r90.flatten()
flattrainoutx = flattrainout0
flattrainoutxx = np.hstack(( flattrainout0, flattrainout0_fllr, flattrainout0_flud, flattrainout0_r180))
flattrainout = np.hstack(( flattrainout0, flattrainout0_fllr, flattrainout0_flud, flattrainout0_r180,
flattrainout0_r270, flattrainout0_r90))
for j in range(contains_train):
if j > 0:
train_inputj = np.array(emi['train'][j]['input'])
 train_inputj_fllr = np.fliplr(train_inputj)
 train_inputj_flud = np.flipud(train_inputj)
 train_inputj_r180 = np.rot90(train_inputj, 2)
 train_inputj_r270 = np.rot90(train_inputj, 3)
 train_inputj_r90 = np.rot90(train_inputj, 1)
 flattraininj = train_inputj.flatten()
flattraininj_fllr = train_inputj_fllr.flatten()
flattraininj_flud = train_inputj_flud.flatten()
flattraininj_r180 = train_inputj_r180.flatten()
flattraininj_r270 = train_inputj_r270.flatten()
flattraininj_r90 = train_inputj_r90.flatten()
flattraininx = np.hstack(( flattraininx, flattraininj))
flattraininxx = np.hstack(( flattraininxx, flattraininj, flattraininj_fllr, flattraininj_flud, flattraininj_r180))
flattrainin = np.hstack(( flattrainin, flattraininj, flattraininj_fllr, flattraininj_flud, flattraininj_r180,
flattraininj_r270, flattraininj_r90))
train_outputj = np.array(emi['train'][j]['output'])
 train_outputj_fllr = np.fliplr(train_outputj)
 train_outputj_flud = np.flipud(train_outputj)
 train_outputj_r180 = np.rot90(train_outputj, 2)
 train_outputj_r270 = np.rot90(train_outputj, 3)
 train_outputj_r90 = np.rot90(train_outputj, 1)
 flattrainoutj = train_outputj.flatten()
flattrainoutj_fllr = train_outputj_fllr.flatten()
flattrainoutj_flud = train_outputj_flud.flatten()
flattrainoutj_r180 = train_outputj_r180.flatten()
flattrainoutj_r270 = train_outputj_r270.flatten()
flattrainoutj_r90 = train_outputj_r90.flatten()
flattrainoutx = np.hstack(( flattrainoutx, flattrainoutj))
flattrainoutxx = np.hstack(( flattrainoutxx, flattrainoutj, flattrainoutj_fllr, flattrainoutj_flud, flattrainoutj_r180))
flattrainout = np.hstack(( flattrainout, flattrainoutj, flattrainoutj_fllr, flattrainoutj_flud, flattrainoutj_r180,
flattrainoutj_r270, flattrainoutj_r90))
test_input0 = np.array(emi['test'][0]['input'])
 test_input = test_input0
flattestin = test_input.flatten()
flatdata = np.hstack(( flattrainin, flattrainout, flattestin))
lb = LabelBinarizer()
zipBinar = lb.fit(flatdata)
 zipdata = zipBinar.transform(flatdata)
 dim = zipdata.shape[1]
df = set(flatdata)
 ziptraininx = zipBinar.transform(flattraininx)
 ziptrainoutx = zipBinar.transform(flattrainoutx)
 ziptraininxx = zipBinar.transform(flattraininxx)
 ziptrainoutxx = zipBinar.transform(flattrainoutxx)
 ziptrainin = zipBinar.transform(flattrainin)
 ziptrainout = zipBinar.transform(flattrainout)
 ziptestin = zipBinar.transform(flattestin)
 print(f'i = {i} >>> ziptraininx.shape: {ziptraininx.shape}...ziptrainoutx.shape: {ziptrainoutx.shape}')
 print(f'i = {i} >>> ziptraininxx.shape: {ziptraininxx.shape}...ziptrainoutxx.shape: {ziptrainoutxx.shape}')
 print(f'i = {i} >>> ziptrainin.shape: {ziptrainin.shape}...ziptrainout.shape: {ziptrainout.shape}')
 print(f'i = {i} >>> ziptestin.shape: {ziptestin.shape}')
 print(f'colors: {df}')
 print()
dimtrainin = flattrainin.shape[0]
dimtrainout = flattrainout.shape[0]
if dimtrainin < dimtrainout:
aaa = 0
if dimtrainin > 1.5 * dimtrainout:
aaa = 0
if np.sum(train_input0)== 0:
aaa = 0
dimin0 = test_input.shape[0]
dimin1 = test_input.shape[1]
dim1 = dim * dimin1
dim2 = dim * dimin0 * dimin1
dim3 = dimin0 * dimin1
neigh1 = KNeighborsClassifier(n_neighbors=3)
 if aaa == 777:
neigh1.fit(ziptrainin, ziptrainout)
 pred1_classes = neigh1.predict(ziptestin)
 pred1_classes = zipBinar.inverse_transform(pred1_classes)
 if test_input0.shape == train_input0.shape :
pr1 = pred1_classes.reshape(-1, train_output0.shape[1])
 if test_input0.shape != train_input0.shape :
pr1 = pred1_classes.reshape(-1, test_input0.shape[1])
 neigh2 = KNeighborsClassifier(n_neighbors=dim)
 if aaa == 777:
neigh2.fit(ziptraininxx, ziptrainoutxx)
 pred2_classes = neigh2.predict(ziptestin)
 pred2_classes = zipBinar.inverse_transform(pred2_classes)
 if test_input0.shape == train_input0.shape :
pr2 = pred2_classes.reshape(-1, train_output0.shape[1])
 if test_input0.shape != train_input0.shape :
pr2 = pred2_classes.reshape(-1, test_input0.shape[1])
 model = tf.keras.Sequential()
model.add(layers.Dense(dim2, activation='relu', input_dim=dim))
model.add(layers.Dense(dim1, activation='relu'))
model.add(layers.Dense(dim, activation='softmax'))
model.summary()
if aaa == 777:
model.compile(loss='binary_crossentropy',
optimizer= 'adam',
metrics=['accuracy'])
 model.fit(ziptrainin, ziptrainout,
epochs=5,
batch_size=dim, verbose=0)
 predicted_classes = model.predict_classes(ziptestin)
 if test_input0.shape == train_input0.shape :
pr3 = predicted_classes.reshape(-1, train_output0.shape[1])
 if test_input0.shape != train_input0.shape :
pr3 = predicted_classes.reshape(-1, test_input0.shape[1])
 if aaa != 777:
if contains_train == 2:
pr1 = train_output0
pr2 = np.array(emi['train'][1]['output'])
 pr3 = test_input0
if contains_train != 2:
pr1 = train_output0
pr2 = np.array(emi['train'][1]['output'])
 pr3 = np.array(emi['train'][2]['output'])
 if train_output0.shape ==(1,1):
if dim > 4:
dflist = list(df)
 pr1 = np.array([[dflist[2]]])
 pr2 = np.array([[dflist[3]]])
 pr3 = np.array([[dflist[4]]])
 def plot_task(task):
cmap = colors.ListedColormap(
 ['
'
norm = colors.Normalize(vmin=0, vmax=9)
 fig, axs = plt.subplots(1, 8, figsize=(15,15))
axs[0].imshow(emi['train'][0]['input'], cmap=cmap, norm=norm)
 axs[0].axis('off')
 axs[0].set_title('Train Input')
 axs[1].imshow(emi['train'][0]['output'], cmap=cmap, norm=norm)
 axs[1].axis('off')
 axs[1].set_title('Train Output')
 axs[2].imshow(emi['train'][1]['input'], cmap=cmap, norm=norm)
 axs[2].axis('off')
 axs[2].set_title('Train Input')
 axs[3].imshow(emi['train'][1]['output'], cmap=cmap, norm=norm)
 axs[3].axis('off')
 axs[3].set_title('Train Output')
 axs[4].imshow(emi['test'][0]['input'], cmap=cmap, norm=norm)
 axs[4].axis('off')
 axs[4].set_title('Test Input')
 axs[5].imshow(pr1, cmap=cmap, norm=norm)
 axs[5].axis('off')
 axs[5].set_title('predicted-1')
 axs[6].imshow(pr2, cmap=cmap, norm=norm)
 axs[6].axis('off')
 axs[6].set_title('predicted-2')
 axs[7].imshow(pr3, cmap=cmap, norm=norm)
 axs[7].axis('off')
 axs[7].set_title('predicted-3')
 plt.tight_layout()
plt.show()
plot_task(task)
 def flattener(pred):
str_pred = str([row for row in pred])
 str_pred = str_pred.replace(', ', '')
 str_pred = str_pred.replace('[[', '|')
 str_pred = str_pred.replace('][', '|')
 str_pred = str_pred.replace(']]', '|')
 return str_pred
prd1 = pr1.tolist()
prd1 = flattener(prd1)
 prd2 = pr2.tolist()
prd2 = flattener(prd2)
 prd3 = pr3.tolist()
prd3 = flattener(prd3)
 prd = prd1 + ' ' + prd2 + ' ' + prd3 + ' '
prdn.append(prd)
 s_tasks = test_tasks[i]
s_tasks = s_tasks.replace('.json', '_0')
 str_tasks.append(s_tasks)
 for output_id in submission.index:
if s_tasks == output_id :
task_id = output_id.split('_')[0]
f = str(test_path / str(task_id + '.json'))
with open(f, 'r')as read_file:
task = json.load(read_file)
 submission.loc[output_id, 'output'] = prd
submission.to_csv(working_path / 'submission.csv')
 submission = pd.read_csv(working_path / 'submission.csv', index_col= 'output_id')
 submission.to_csv('submission.csv')
<set_options>
train_csv = pd.read_csv(".. /input/titanic/train.csv")
 test_csv = pd.read_csv(".. /input/titanic/test.csv" )
np.seterr(divide='ignore', invalid='ignore')
<define_variables>
train_csv = train_csv.drop(["PassengerId", "Name", "Ticket","Cabin"], axis = 1)
 train_csv.head(3 )
train_path = '/kaggle/input/abstraction-and-reasoning-challenge/training/'
evaluation_path = '/kaggle/input/abstraction-and-reasoning-challenge/evaluation/'
test_path = '/kaggle/input/abstraction-and-reasoning-challenge/test/'<categorify>
test_csv = test_csv.drop(["Name", "Ticket","Cabin"],axis = 1)
 test_csv.head(3 )
def get_im_with_same_ioshape(file_path, name, show=False, mode='train'):
train = []
test = []
with open(file_path+name, 'r')as train_file:
all_im = json.load(train_file)
 im_in = np.array(all_im['train'][0]['input'])
 im_out = np.array(all_im['train'][0]['output'])
 if im_in.shape != im_out.shape:
return None
for im in all_im['train']:
im_in = np.array(im['input'])
 im_out = np.array(im['output'])
 mask = np.asarray(np.nan_to_num(( im_in-im_out)/(im_in-im_out), 0), 'int8')
 train.append(( im_in, im_out, mask))
if show:
print("NAME:
",name)
 print("IN:
")
 plt.imshow(im_in)
 plt.show()
print("OUT:
")
 plt.imshow(im_out)
 plt.show()
print("MASK:
")
 plt.imshow(mask)
 plt.show()
if mode=='train':
for im in all_im['test']:
im_in = np.array(im['input'])
 im_out = np.array(im['output'])
 test.append(( im_in, im_out))
if mode=='test':
for im in all_im['test']:
im_in = np.array(im['input'])
 test.append(( im_in))
return train, test
train, test = get_im_with_same_ioshape(data_path,same_shape[0], show=False )<feature_engineering>
train_csv.isnull().sum()
def get_features(input_, flipping=False, rotate=False, center=True, da=1):
im_in,im_out, mask = input_
size=sum(sum(mask))
if flipping:
size*=4
if rotate:
size*=(7/4)
 size = int(size)
 features = np.zeros(( size,9))
colors = np.zeros(size)
 f=0
for y in range(mask.shape[0]):
for x in range(mask.shape[1]):
if mask[y,x]==1:
pix_exp = np.zeros(( 2*da+1)**2)
 n_p=0
for dy in range(-da,da+1):
for dx in range(-da,da+1):
if dy!=0 or dx!=0:
if dx+x>=0 and dy+y>=0 and dx+x<mask.shape[1] and dy+y<mask.shape[0]:
pix_exp[n_p]=im_in[y+dy, x+dx]
else:
pix_exp[n_p]=-1
else:
if center:
pix_exp[n_p]=im_in[y, x]
else:
pix_exp[n_p]=-2
n_p+=1
features[f] = pix_exp
colors[f] = im_out[y, x]
f+=1
if flipping:
features[f] = np.flipud(pix_exp.reshape(3,3)).flatten()
colors[f] = im_out[y, x]
f+=1
features[f] = np.fliplr(pix_exp.reshape(3,3)).flatten()
colors[f] = im_out[y, x]
f+=1
features[f] = np.flip(pix_exp.reshape(3,3),(0, 1)).flatten()
colors[f] = im_out[y, x]
f+=1
if rotate:
features[f] = np.rot90(pix_exp.reshape(3,3), 1 ).flatten()
colors[f] = im_out[y, x]
f+=1
features[f] = np.rot90(pix_exp.reshape(3,3), 2 ).flatten()
colors[f] = im_out[y, x]
f+=1
features[f] = np.rot90(pix_exp.reshape(3,3), 3 ).flatten()
colors[f] = im_out[y, x]
f+=1
return features, colors 
<feature_engineering>
pd.value_counts(train_csv["Embarked"] )
@jit(nopython=False)
 def get_cf(train, flipping=False, rotate=False, center=True):
features_set = []
colors_set = []
for in_out_mask in train:
features, colors = get_features(in_out_mask, flipping, rotate, center)
 features_set+=list(features)
 colors_set+=list(colors)
 features_set_min = np.unique(np.array(features_set), axis = 0)
 colors_min = np.zeros(len(features_set_min))
for n, feature in enumerate(features_set):
for i ,feature_uniq in enumerate(features_set_min):
if str(feature_uniq)==str(feature):
colors_min[i]=colors_set[n]
break
return colors_min, features_set_min
colors_min, features_set_min = get_cf(train, flipping=False, rotate=False, center=True)
 print(colors_min)
 print(features_set_min )<train_model>
_ = train_csv.fillna({"Embarked" : "S"}, inplace = True)
 _ = train_csv.fillna({"Age" : 29.699}, inplace = True )
def make_pred(im_in, features, colors, it=1, solver=None, center=True):
if solver=="KNN":
model = KNN(2)
 model.fit(X=features, y=colors)
 elif solver=="RF":
model = RF()
model.fit(X=features, y=colors)
 elif solver=="DT":
model = DT()
model.fit(X=features, y=colors)
 for epoch in range(it):
im_out = im_in.copy()
f=0
for y in range(im_in.shape[0]):
for x in range(im_in.shape[1]):
pix_exp = np.zeros(9)
 n_p=0
for dy in range(-1,2):
for dx in range(-1,2):
if dy!=0 or dx!=0:
if dx+x>=0 and dy+y>=0 and dx+x<im_in.shape[1] and dy+y<im_in.shape[0]:
pix_exp[n_p]=im_in[y+dy, x+dx]
else:
pix_exp[n_p]=-1
else:
if center:
pix_exp[n_p]=im_in[y, x]
else:
pix_exp[n_p]=-2
n_p+=1
if solver==None:
for n, f in enumerate(features):
if str(f)==str(pix_exp):
im_out[y,x]=colors[n]
else:
im_out[y,x]=model.predict([pix_exp])
 im_in=im_out.copy()
return im_out
pred=make_pred(test[0][0], features_set_min, colors_min, 1, "DT", True)
 print("INPUT")
 plt.imshow(test[0][0])
 plt.show()
print("PREDICT")
 plt.imshow(pred)
 plt.show()
print("OUTPUT")
 plt.imshow(test[0][1])
 plt.show() 
<load_from_csv>
test_csv.isnull().sum()
sample = pd.read_csv("/kaggle/input/abstraction-and-reasoning-challenge/sample_submission.csv" )<categorify>
_ = test_csv.fillna({"Fare" : 35.627}, inplace = True)
 _ = test_csv.fillna({"Age" : 30.272}, inplace = True )
def flattener(grid):
grid = grid.astype('uint8' ).tolist()
str_pred = str([row for row in grid])
 str_pred = str_pred.replace(', ', '')
 str_pred = str_pred.replace('[[', '|')
 str_pred = str_pred.replace('][', '|')
 str_pred = str_pred.replace(']]', '|')
 return str_pred<predict_on_test>
LE = LabelEncoder()
labels = ["Embarked", "Sex"]
for label in labels:
train_csv[label] = LE.fit_transform(train_csv[label])
 test_csv[label] = LE.fit_transform(test_csv[label] )
num=0
for test_name in tqdm.tqdm(sample.output_id):
name = test_name.split('_')[0]+'.json'
index=int(test_name.split('_')[1])
 data = get_im_with_same_ioshape(test_path, name, False, 'test')
 if data!=None:
train, test = data
colors, features = get_cf(train, True, True, True)
 pred = make_pred(test[index], features, colors, 1, None, True)
 colors1, features1 = get_cf(train, False, False, True)
 pred1 = make_pred(test[index], features1, colors1, 1, "DT", True)
 colors2, features2 = get_cf(train, False, False, False)
 pred2 = make_pred(test[index], features2, colors2, 1, None, False)
 sample.output[num] = ' '.join([flattener(pred), flattener(pred1), flattener(pred2)])
 num+=1 
<save_to_csv>
x = train_csv.drop(["Survived"], axis = 1)
 y = train_csv["Survived"]
sample.to_csv('submission.csv', index = False )<import_modules>
import keras
from keras.models import Sequential
from keras.layers import Dense, Activation, Dropout
from keras.layers.advanced_activations import LeakyReLU
import numpy as np
import pandas as pd
from tqdm import tqdm<load_pretrained>
alpha = 0.01
dropout = 0.3
epochs = 300
batch_size = 32
model = Sequential()
model.add(Dense(7,input_dim = 7))
model.add(LeakyReLU(alpha = alpha))
model.add(Dropout(dropout))
model.add(Dense(100))
model.add(LeakyReLU(alpha = alpha))
model.add(Dropout(dropout))
model.add(Dense(50))
model.add(LeakyReLU(alpha = alpha))
model.add(Dropout(dropout))
model.add(Dense(25))
model.add(LeakyReLU(alpha = alpha))
model.add(Dropout(dropout))
model.add(Dense(10))
model.add(LeakyReLU(alpha = alpha))
model.add(Dropout(dropout))
model.add(Dense(5))
model.add(LeakyReLU(alpha = alpha))
model.add(Dropout(dropout))
model.add(Dense(1, activation = 'sigmoid'))
model.summary()
def load_data(path):
tasks = pd.Series()
for file_path in os.listdir(path):
task_file = path_join(path, file_path)
 with open(task_file, 'r')as f:
task = json.load(f)
 tasks[file_path[:-5]] = task
return tasks<load_pretrained>
model.compile(loss = 'binary_crossentropy', optimizer = 'Nadam', metrics = ['accuracy'])
 result = model.fit(x, y, epochs = epochs, batch_size = batch_size )
train_tasks = load_data('.. /input/abstraction-and-reasoning-challenge/training/')
 evaluation_tasks = load_data('.. /input/abstraction-and-reasoning-challenge/evaluation/')
 test_tasks = load_data('.. /input/abstraction-and-reasoning-challenge/test/')
 train_tasks.head()<import_modules>
test_data = test_csv.drop(['PassengerId'], axis = 1)
 predict = np.round(model.predict(test_data))
prediction = pd.DataFrame(predict )
class CAModel(nn.Module):
def __init__(self, num_states):
super(CAModel, self ).__init__()
self.simple_conv = nn.Sequential(
 nn.Conv2d(num_states, 32, kernel_size=3, padding=1),
nn.ReLU() 
)
 self.conv1 = nn.Conv2d(32, num_states, kernel_size=1)
 self.conv2 = nn.Conv2d(32, num_states+1, kernel_size=1)
 self.soft = nn.Softmax(dim=1)
 def forward(self, x, steps = 1):
for step in range(steps):
x = self.simple_conv(x)
 y1 = self.conv1(x)
 y2 = self.conv2(x)
 x = self.soft(y1)
 return y1, y2<categorify>
submission = pd.concat([test_csv[['PassengerId']],prediction],axis = 1)
 submission = submission.rename(columns = {0 : 'Survived'})
 _ = submission.fillna({'Survived' : 0}, inplace = True)
 submission = submission.astype(np.int64)
 submission.head()
def inp2img(inp):
inp = np.array(inp)
 img = np.full(( 10, inp.shape[0], inp.shape[1]), 0, dtype=np.uint8)
 for i in range(10):
img[i] =(inp==i)
 return img
def target_maker(samin, samout):
target = np.full(( len(samin), len(samin[0])) , 0, dtype=np.uint8)
 for i in range(len(samin)) :
for j in range(len(samin[0])) :
if samin[i][j]==samout[i][j]:
target[i,j] = 10
else:
target[i,j] = samout[i][j]
return target
def pred_maker(inp, pred, pred_grade):
inp = np.asarray(inp)
 final_pred = np.full(( inp.shape[0], inp.shape[1]), 0, dtype=np.uint8)
 grade_avg = np.mean(pred_grade)
 threshold = 0.66
for i in range(pred.shape[0]):
for j in range(pred.shape[1]):
if pred[i,j] == 10 or pred_grade[i, j]/grade_avg < threshold:
final_pred[i,j] = inp[i,j]
else:
final_pred[i,j] = pred[i,j]
return final_pred
class TaskSolver:
def train(self, task_train, n_epoch=100, max_steps=2):

 self.net = CAModel(10)
 criterion = CrossEntropyLoss()
optimizer = Adam(self.net.parameters() , lr = 0.01)
 for epoch in range(n_epoch):
optimizer.zero_grad()
for sample in task_train:
target = target_maker(sample['input'],sample['output'])
 inputs = FloatTensor(inp2img(sample['input'])).unsqueeze(dim=0)
 labels1 = LongTensor(sample['output'] ).unsqueeze(dim=0)
 labels2 = LongTensor(target ).unsqueeze(dim=0)
 outputs1 = self.net(inputs)[0]
outputs2 = self.net(inputs)[1]
loss = criterion(outputs1, labels1)
 loss.backward()
loss = criterion(outputs2, labels2)
 loss.backward()
optimizer.step()
return self
def predict(self, task_test):
predictions = []
pred_grades = []
with torch.no_grad() :
for sample in task_test:
inputs = FloatTensor(inp2img(sample['input'])).unsqueeze(dim=0)
 outputs = self.net(inputs)[0]
pred = outputs.squeeze(dim=0 ).cpu().numpy().argmax(0)
 final_pred = pred
predictions.append(final_pred)
 return predictions<compute_test_metric>
submission.to_csv("submission.csv", index = False )