Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<statistical_test>
%matplotlib inline
np.random.seed(2)
 sns.set(style='white', context='notebook', palette='deep' )
def butter_lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
 return b, a
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
 y = lfilter(b, a, data)
 return y<categorify>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
def peak_accel_threshold(data, timestamps, threshold):
d_acc = []
last_state = 'below'
crest_troughs = 0
crossings = []
for i, datum in enumerate(data):
current_state = last_state
if datum < threshold:
current_state = 'below'
elif datum > threshold:
current_state = 'above'
if current_state is not last_state:
if current_state is 'above':
crossing = [timestamps[i], threshold]
crossings.append(crossing)
 else:
crossing = [timestamps[i], threshold]
crossings.append(crossing)
 crest_troughs += 1
last_state = current_state
return np.array(crossings )<split>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
def steps_compute_rel_positions(sample_file):
mix_acce = np.sqrt(sample_file.acce[:,1:2]**2 + sample_file.acce[:,2:3]**2 + sample_file.acce[:,3:4]**2)
 mix_acce = np.concatenate([sample_file.acce[:,0:1], mix_acce], 1)
 mix_df = pd.DataFrame(mix_acce)
 mix_df.columns = ["timestamp","acce"]
filtered = butter_lowpass_filter(mix_df["acce"], cutoff, fs, order)
 threshold = filtered.mean() * 1.1
crossings = peak_accel_threshold(filtered, mix_df["timestamp"], threshold)
 step_sum = len(crossings)/2
distance = w_height * 0.4 * step_sum
mag_df = pd.DataFrame(sample_file.magn)
 mag_df.columns = ["timestamp","x","y","z"]
acce_df = pd.DataFrame(sample_file.acce)
 acce_df.columns = ["timestamp","ax","ay","az"]
mag_df = pd.merge(mag_df,acce_df,on="timestamp")
 mag_df.dropna()
time_di_list = []
for i in mag_df.iterrows() :
gx,gy,gz = i[1][1],i[1][2],i[1][3]
ax,ay,az = i[1][4],i[1][5],i[1][6]
roll = math.atan2(ay,az)
 pitch = math.atan2(-1*ax ,(ay * math.sin(roll)+ az * math.cos(roll)))
 q = m_trans - math.degrees(math.atan2(
(gz*math.sin(roll)-gy*math.cos(roll)) ,(gx*math.cos(pitch)+ gy*math.sin(roll)*math.sin(pitch)+ gz*math.sin(pitch)*math.cos(roll)) 
)) -90
if q <= 0:
q += 360
time_di_list.append(( i[1][0],q))
d_list = [x[1] for x in time_di_list]
steps = []
step_time = []
di_dict = dict(time_di_list)
 for n,i in enumerate(crossings[:,:1]):
if n % 2 == 1:
continue
direct_now = di_dict[i[0]]
dx = math.sin(math.radians(direct_now))
dy = math.cos(math.radians(direct_now))
steps.append(( i[0],dx,dy))
step_time.append(i[0])
 step_dtime = np.diff(step_time)/1000
step_dtime = step_dtime.tolist()
step_dtime.insert(0,5)
 rel_position = []
wp_idx = 0
for p,i in enumerate(steps):
step_distance = 0
if step_dtime[p] >= 1:
step_distance = w_height*0.25
elif step_dtime[p] >= 0.75:
step_distance = w_height*0.3
elif step_dtime[p] >= 0.5:
step_distance = w_height*0.4
elif step_dtime[p] >= 0.35:
step_distance = w_height*0.45
elif step_dtime[p] >= 0.2:
step_distance = w_height*0.5
else:
step_distance = w_height*0.4
rel_position.append([i[0], i[1]*step_distance, i[2]*step_distance])
 return np.array(rel_position )<feature_engineering>
X_train = X_train / 255.0
test = test / 255.0
def correct_path(args):
path, path_df = args
T_ref = path_df['timestamp'].values
xy_hat = path_df[['x', 'y']].values
example = read_data_file(f'{INPUT_PATH}/test/{path}.txt')
 rel_positions1 = compute_rel_positions(example.acce, example.ahrs)
 rel_positions2 = steps_compute_rel_positions(example)
 rel1 = rel_positions1.copy()
rel2 = rel_positions2.copy()
rel1[:,1:] = rel_positions1[:,1:] / 2
rel2[:,1:] = rel_positions2[:,1:] / 2
rel_positions = np.vstack([rel1,rel2])
 rel_positions = rel_positions[np.argsort(rel_positions[:, 0])]
if T_ref[-1] > rel_positions[-1, 0]:
rel_positions = [np.array([[0, 0, 0]]), rel_positions, np.array([[T_ref[-1], 0, 0]])]
else:
rel_positions = [np.array([[0, 0, 0]]), rel_positions]
rel_positions = np.concatenate(rel_positions)
 T_rel = rel_positions[:, 0]
delta_xy_hat = np.diff(scipy.interpolate.interp1d(T_rel, np.cumsum(rel_positions[:, 1:3], axis=0), axis=0 )(T_ref), axis=0)
 N = xy_hat.shape[0]
delta_t = np.diff(T_ref)
 alpha =(8.1)**(-2)* np.ones(N)
 beta =(0.3 + 0.3 * 1e-3 * delta_t)**(-2)
 A = scipy.sparse.spdiags(alpha, [0], N, N)
 B = scipy.sparse.spdiags(beta, [0], N-1, N-1)
 D = scipy.sparse.spdiags(np.stack([-np.ones(N), np.ones(N)]), [0, 1], N-1, N)
 Q = A +(D.T @ B @ D)
 c =(A @ xy_hat)+(D.T @(B @ delta_xy_hat))
xy_star = scipy.sparse.linalg.spsolve(Q, c)
 return pd.DataFrame({
'site_path_timestamp' : path_df['site_path_timestamp'],
'floor' : path_df['floor'],
'x' : xy_star[:, 0],
'y' : xy_star[:, 1],
} )<save_to_csv>
X_train = X_train.values.reshape(-1,28,28,1)
 test = test.values.reshape(-1,28,28,1 )
sub = pd.read_csv('.. /input/indoor-loc-and-nav-subs/submission_4475.csv')
 tmp = sub['site_path_timestamp'].apply(lambda s : pd.Series(s.split('_')))
 sub['site'] = tmp[0]
sub['path'] = tmp[1]
sub['timestamp'] = tmp[2].astype(float)
 processes = multiprocessing.cpu_count()
with multiprocessing.Pool(processes=processes)as pool:
dfs = pool.imap_unordered(correct_path, sub.groupby('path'))
dfs = tqdm(dfs)
 dfs = list(dfs)
 sub = pd.concat(dfs ).sort_values('site_path_timestamp')
 sub.to_csv('submission.csv', index=False )<define_variables>
Y_train = to_categorical(Y_train, num_classes = 10)
%matplotlib inline
dfk = pd.DataFrame({
'Kernel ID': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
'Score' : [7.110, 6.674, 6.290, 6.189, 6.077, 6.062, 5.995, 5.694, 5.471, 5.847],
'File Path': ['.. /input/1-3-indoor-navigation-cost-minimization-floor/a9773cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/b9530cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/c8500cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/d8418cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/e8333cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/f8073cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/g7745cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/h7661cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/i7274cm99.csv', '.. /input/1-3-indoor-navigation-cost-minimization-floor/j7285cm99.csv']
})
 dfk<prepare_x_and_y>
X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.1, random_state=2 )
ff1x = 0.60
ff1y = 0.60
ff2x = 0.60
ff2y = 0.60
ff3x = 0.90
ff3y = 0.90
ff4x = 0.95
ff4y = 0.95
main = pd.read_csv(dfk.iloc[8, 2])
 support = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated1 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
sx , sy = [] , []
sx = support.iloc[:, 2].tolist()
sy = support.iloc[:, 3].tolist()
kx = [[],[],[],[],[],[]]
ky = [[],[],[],[],[],[]]
for n in range(6):
kernel = pd.read_csv(dfk.iloc[n, 2])
 kx[n] = kernel.iloc[:, 2].tolist()
ky[n] = kernel.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(sx[j] *(1.- ff1x))
ey =(my[j] * ff1y)+(sy[j] *(1.- ff1y))
if(mx[j] >= sx[j]):
a = mx[j]
b = sx[j]
else:
a = sx[j]
b = mx[j]
if(my[j] >= sy[j]):
c = my[j]
d = sy[j]
else:
c = sy[j]
d = my[j]
for k in range(5, 6):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff2x)+(kx[k][j] *(1.- ff2x))
ey =(ey * ff2y)+(ky[k][j] *(1.- ff2y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 for k in range(3, 5):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff3x)+(kx[k][j] *(1.- ff3x))
ey =(ey * ff3y)+(ky[k][j] *(1.- ff3y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 for k in range(3):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff4x)+(kx[k][j] *(1.- ff4x))
ey =(ey * ff4y)+(ky[k][j] *(1.- ff4y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 rx.append(ex)
 ry.append(ey)
 generated1.iloc[:, 2] = rx
generated1.iloc[:, 3] = ry 
<prepare_x_and_y>
sns.set(style='white', context='notebook', palette='deep' )
ff1x = 0.60
ff1y = 0.60
ff2x = 0.60
ff2y = 0.60
ff3x = 0.90
ff3y = 0.90
ff4x = 0.95
ff4y = 0.95
main = pd.read_csv(dfk.iloc[7, 2])
 support = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated2 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
sx , sy = [] , []
sx = support.iloc[:, 2].tolist()
sy = support.iloc[:, 3].tolist()
kx = [[],[],[],[],[],[]]
ky = [[],[],[],[],[],[]]
for n in range(6):
kernel = pd.read_csv(dfk.iloc[n, 2])
 kx[n] = kernel.iloc[:, 2].tolist()
ky[n] = kernel.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(sx[j] *(1.- ff1x))
ey =(my[j] * ff1y)+(sy[j] *(1.- ff1y))
if(mx[j] >= sx[j]):
a = mx[j]
b = sx[j]
else:
a = sx[j]
b = mx[j]
if(my[j] >= sy[j]):
c = my[j]
d = sy[j]
else:
c = sy[j]
d = my[j]
for k in range(5, 6):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff2x)+(kx[k][j] *(1.- ff2x))
ey =(ey * ff2y)+(ky[k][j] *(1.- ff2y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 for k in range(3, 5):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff3x)+(kx[k][j] *(1.- ff3x))
ey =(ey * ff3y)+(ky[k][j] *(1.- ff3y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 for k in range(3):
if(( b <= kx[k][j] <= a)and(d <= ky[k][j] <= c)) :
ex =(ex * ff4x)+(kx[k][j] *(1.- ff4x))
ey =(ey * ff4y)+(ky[k][j] *(1.- ff4y))
print(f'Row:{j}\t Kernel Number:{k}\t Floor:{mz[j]}')
 print(f'Main:({mx[j]},{my[j]})
 Support:({sx[j]},{sy[j]})
 Kernel:({kx[k][j]},{ky[k][j]})
 Result:({ex},{ey})
 ')
 rx.append(ex)
 ry.append(ey)
 generated2.iloc[:, 2] = rx
generated2.iloc[:, 3] = ry 
<prepare_x_and_y>
model = Sequential()
model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu', input_shape =(28,28,1)))
 model.add(Conv2D(filters = 32, kernel_size =(5,5),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2)))
 model.add(Dropout(0.25))
ff1x = 0.60
ff1y = 0.60
main = generated1
support = generated2
rx , ry = [] , []
generated3 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
sx , sy = [] , []
sx = support.iloc[:, 2].tolist()
sy = support.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(sx[j] *(1.- ff1x))
ey =(my[j] * ff1y)+(sy[j] *(1.- ff1y))
rx.append(ex)
 ry.append(ey)
 generated3.iloc[:, 2] = rx
generated3.iloc[:, 3] = ry 
<prepare_x_and_y>
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2)) )
ff1x = 0.44
ff1y = 0.44
ff2x = 0.24
ff2y = 0.24
ff3x = 0.32
ff3y = 0.32
main = pd.read_csv(dfk.iloc[8, 2])
 support1 = pd.read_csv(dfk.iloc[7, 2])
 support2 = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated4 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
s1x , s1y = [] , []
s1x = support1.iloc[:, 2].tolist()
s1y = support1.iloc[:, 3].tolist()
s2x , s2y = [] , []
s2x = support2.iloc[:, 2].tolist()
s2y = support2.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(s1x[j] * ff2x)+(s2x[j] * ff3x)
 ey =(my[j] * ff1y)+(s1y[j] * ff2y)+(s2y[j] * ff3y)
 rx.append(ex)
 ry.append(ey)
 generated4.iloc[:, 2] = rx
generated4.iloc[:, 3] = ry 
<prepare_x_and_y>
model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2)))
 model.add(Conv2D(filters = 64, kernel_size =(3,3),padding = 'Same',
activation ='relu'))
model.add(AvgPool2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.25))
ff1x = 0.50
ff1y = 0.50
main = generated3
support = generated4
rx , ry = [] , []
generated5 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
sx , sy = [] , []
sx = support.iloc[:, 2].tolist()
sy = support.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(sx[j] *(1.- ff1x))
ey =(my[j] * ff1y)+(sy[j] *(1.- ff1y))
rx.append(ex)
 ry.append(ey)
 generated5.iloc[:, 2] = rx
generated5.iloc[:, 3] = ry 
<prepare_x_and_y>
model.add(Flatten())
 model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(10, activation = "softmax"))
ff1x = 0.40
ff1y = 0.40
ff2x = 0.25
ff2y = 0.25
ff3x = 0.35
ff3y = 0.35
main = pd.read_csv(dfk.iloc[8, 2])
 support1 = pd.read_csv(dfk.iloc[7, 2])
 support2 = pd.read_csv(dfk.iloc[6, 2])
 rx , ry = [] , []
generated6 = main.copy()
mx , my , mz = [] , [] , []
mx = main.iloc[:, 2].tolist()
my = main.iloc[:, 3].tolist()
mz = main.iloc[:, 1].tolist()
s1x , s1y = [] , []
s1x = support1.iloc[:, 2].tolist()
s1y = support1.iloc[:, 3].tolist()
s2x , s2y = [] , []
s2x = support2.iloc[:, 2].tolist()
s2y = support2.iloc[:, 3].tolist()
for j in range(len(main)) :
ex =(mx[j] * ff1x)+(s1x[j] * ff2x)+(s2x[j] * ff3x)
 ey =(my[j] * ff1y)+(s1y[j] * ff2y)+(s2y[j] * ff3y)
 rx.append(ex)
 ry.append(ey)
 generated6.iloc[:, 2] = rx
generated6.iloc[:, 3] = ry 
<save_to_csv>
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0 )
sub = generated5
sub.to_csv("submission.csv", index=False)
 generated1.to_csv("generated1.csv", index=False)
 generated2.to_csv("generated2.csv", index=False)
 generated3.to_csv("generated3.csv", index=False)
 generated4.to_csv("generated4.csv", index=False)
 generated5.to_csv("generated5.csv", index=False)
 generated6.to_csv("generated6.csv", index=False)
 !ls<load_from_zip>
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"] )
!git clone --depth 1 https://github.com/location-competition/indoor-location-competition-20 indoor_location_competition_20
!rm -rf indoor_location_competition_20/data<set_options>
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc',
patience=3,
verbose=1,
factor=0.5,
min_lr=0.00001 )
%matplotlib inline<define_variables>
epochs = 30
batch_size = 64
INPUT_PATH = '.. /input/indoor-location-navigation'<load_from_csv>
history = model.fit(X_train, Y_train, batch_size = batch_size, epochs = epochs,
validation_data =(X_val, Y_val),callbacks=[learning_rate_reduction] )
dfk = pd.DataFrame({
'Kernel ID': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
'Score': [9.773, 9.530, 8.500, 8.418, 8.333, 8.073, 7.745, 7.661, 7.274, 7.285],
'File Path': ['.. /input/indoor9773/Indoor9773.csv', '.. /input/indoor9530/Indoor9530.csv', '.. /input/indoor8500/Indoor8500.csv', '.. /input/indoor8418/Indoor8418.csv', '.. /input/indoor8333/Indoor8333.csv', '.. /input/indoor8073/Indoor8073.csv', '.. /input/indoornav7745sub/submission.csv', '.. /input/indoor7661/Indoor7661.csv', '.. /input/indoor-wifi-floor/submission.csv', '.. /input/time-series-rnn-xy-prediction/submission.csv']
})
 dfk<feature_engineering>
results = model.predict(test )
def compute_rel_positions(acce_datas, ahrs_datas):
step_timestamps, step_indexs, step_acce_max_mins = compute_f.compute_steps(acce_datas)
 headings = compute_f.compute_headings(ahrs_datas)
 stride_lengths = compute_f.compute_stride_length(step_acce_max_mins)
 step_headings = compute_f.compute_step_heading(step_timestamps, headings)
 rel_positions = compute_f.compute_rel_positions(stride_lengths, step_headings)
 return rel_positions<load_from_csv>
results = np.argmax(results,axis = 1)
def correct_path(args):
path, path_df = args
T_ref = path_df['timestamp'].values
xy_hat = path_df[['x', 'y']].values
example = read_data_file(f'{INPUT_PATH}/test/{path}.txt')
 rel_positions = compute_rel_positions(example.acce, example.ahrs)
 if T_ref[-1] > rel_positions[-1, 0]:
rel_positions = [np.array([[0, 0, 0]]), rel_positions, np.array([[T_ref[-1], 0, 0]])]
else:
rel_positions = [np.array([[0, 0, 0]]), rel_positions]
rel_positions = np.concatenate(rel_positions)
 T_rel = rel_positions[:, 0]
delta_xy_hat = np.diff(scipy.interpolate.interp1d(T_rel, np.cumsum(rel_positions[:, 1:3], axis=0), axis=0 )(T_ref), axis=0)
 N = xy_hat.shape[0]
delta_t = np.diff(T_ref)
 alpha =(8.1)**(-2)* np.ones(N)
 beta =(0.30 + 0.30 * 1e-3 * delta_t)**(-2)
 A = scipy.sparse.spdiags(alpha, [0], N, N)
 B = scipy.sparse.spdiags(beta, [0], N-1, N-1)
 D = scipy.sparse.spdiags(np.stack([-np.ones(N), np.ones(N)]), [0, 1], N-1, N)
 Q = A +(D.T @ B @ D)
 c =(A @ xy_hat)+(D.T @(B @ delta_xy_hat))
xy_star = scipy.sparse.linalg.spsolve(Q, c)
 return pd.DataFrame({
'site_path_timestamp' : path_df['site_path_timestamp'],
'floor' : path_df['floor'],
'x' : xy_star[:, 0],
'y' : xy_star[:, 1],
})
<feature_engineering>
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1 )
<save_to_csv><EOS> 
submission.to_csv("SM.csv",index=False )