Kaggle competition: Mechanisms of Action (MoA) Prediction
<SOS> metric: MeanColumnwiseLogLoss Kaggle data source: mechanisms-of-action-(moa)-prediction<import_modules>
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import random
import time
import tensorflow as tf
import tensorflow.keras.layers as L
import tensorflow.keras.models as M
import tensorflow.keras.backend as K
import tensorflow.keras.backend as B
import tensorflow_addons as tfa
from keras.models import Model
from sklearn.decomposition import PCA
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split, KFold
from sklearn.metrics import log_loss
from sklearn.utils import shuffle
from sklearn.mixture import BayesianGaussianMixture
from sklearn.cluster import KMeans
from statsmodels.tsa.statespace.sarimax import SARIMAX<define_variables>
data_folder = '.. /input/lish-moa/'
train=pd.read_csv(data_folder + '/train_features.csv')
 test=pd.read_csv(data_folder + '/test_features.csv')
 targets=pd.read_csv(data_folder + '/train_targets_scored.csv')
 targets_ns = pd.read_csv(data_folder + '/train_targets_nonscored.csv')
 drug_table = pd.read_csv(data_folder + '/train_drug.csv')
 train.head()
count_len = len(train_df[train_df['Country_Region'] == 'Russia'])
 train_cc = []
train_f = []
count = 0
for i in range(int(len(train_df)/ count_len)) :
train_cc.append(train_df.ConfirmedCases[count:count+count_len].values.tolist())
 train_f.append(train_df.Fatalities[count:count+count_len].values.tolist())
 count += count_len<define_search_space>
print('Train rows:', len(train.index))
print('Test rows:', len(test.index))
tag = 'tag'
train[tag] = 'train'
test[tag] = 'test'
total=pd.concat([train, test])
 print('Total rows:', len(total.index))
delta =(date(2020, 4, 15)- date(2020, 4, 2)).days<train_on_grid>
columns = train.columns.to_list()
c_columns = [col for col in columns if col.startswith('c-')]
print('Number of c_cols:', len(c_columns))
g_columns = [col for col in columns if col.startswith('g-')]
print('Number of g_cols:', len(g_columns))
test_count = len(test_df[test_df['Country_Region'] == 'Russia'])- delta - 1
predicted_cc = []
for i in range(len(train_cc)) :
try:
data1 = train_cc[i]
model1 = SARIMAX(data1, order=(1,1,0), seasonal_order=(1,1,0,12), measurement_error=True)
 model1_fit = model1.fit(disp=False)
 predicted1 = model1_fit.predict(len(data1), len(data1)+test_count)
 predicted_cc.append(predicted1.tolist())
 except:
data1 = train_cc[i]
model1 = SARIMAX(data1,order=(1,1,0),seasonal_order=(1,1,0,12),measurement_error=True,enforce_stationarity=False)
 model1_fit = model1.fit(disp=False)
 predicted1 = model1_fit.predict(len(data1), len(data1)+test_count)
 predicted_cc.append(predicted1.tolist() )<train_on_grid>
vehicles=total.loc[total[type_col]=='ctl_vehicle']
print('Total vehicles:',len(vehicles.index))
predicted_f = []
for i in range(len(train_f)) :
try:
data2 = train_f[i]
model2 = SARIMAX(data2,order=(1,1,0), seasonal_order=(1,1,0,12), measurement_error=True)
 model2_fit = model2.fit(disp=False)
 predicted2 = model2_fit.predict(len(data2), len(data2)+test_count)
 predicted_f.append(predicted2.tolist())
 except:
data2 = train_f[i]
model2 = SARIMAX(data2,order=(1,1,0),seasonal_order=(1,1,0,12),measurement_error=True,enforce_stationarity=False)
 model2_fit = model2.fit(disp=False)
 predicted2 = model2_fit.predict(len(data2), len(data2)+test_count)
 predicted_f.append(predicted2.tolist() )<train_model>
targets_agg = targets.agg([sum])
 targets_agg.drop(['sig_id'], axis=1,inplace=True)
 target_col = targets_agg.columns
np.sort(targets_agg.values)
 zero_targets = targets_agg[targets_agg.columns[(targets_agg<10 ).any() ]]
zero_targets
check_lenght = len(train_cc[0][-delta:])+ len(predicted_cc[0])
 if check_lenght == 43:
print('Check OK')
 else:
print('Check failed' )<sort_values>
drug_id = 'drug_id'
drug_targets = pd.concat([drug_table[drug_id], targets], axis = 1)
 grouped = drug_targets.groupby(drug_id)
 drug_examples = grouped[drug_id].count()
train_ids = train[id_col]
train_nums = grouped[drug_id].transform('count' )
predicted_ConfirmedCases = []
predicted_Fatalities = []
for i in range(int(len(train_df)/ count_len)) :
predicted_ConfirmedCases.append(train_cc[i][-delta:])
 predicted_ConfirmedCases.append(predicted_cc[i])
 predicted_Fatalities.append(train_f[i][-delta:])
 predicted_Fatalities.append(predicted_f[i])
 predicted_ConfirmedCases = list(itertools.chain.from_iterable(predicted_ConfirmedCases))
predicted_Fatalities = list(itertools.chain.from_iterable(predicted_Fatalities))<save_to_csv>
total2 = total.copy()
targets2 = targets.copy()
scored_columns = targets2.columns
scored_columns = scored_columns.drop('sig_id')
 num_scored = len(scored_columns)
 targets2 = pd.concat([targets2, targets_ns], axis = 1)
 total2[dose_col]=total2[dose_col].map({'D1':0, 'D2':1})
 def onehot_time(x):
return [(x==24 ).astype(int),(x==48 ).astype(int),(x==72 ).astype(int)]
total2['t1'], total2['t2'], total2['t3'] = onehot_time(total2[time_col])
 total2.drop([time_col], axis=1, inplace=True)
 total2.drop([tag], axis=1, inplace=True)
 vehicles_mask = total2[type_col] == 'ctl_vehicle'
n_train = len(targets2.index)
 vehicles = total2[vehicles_mask]
total2 = total2[~vehicles_mask]
targets2 = targets2[~vehicles_mask[:n_train]]
train_nums2 = train_nums[~vehicles_mask[:n_train]]
train_nums2 = np.array(train_nums2.to_list())
 total2.drop([type_col], axis=1, inplace=True)
 vehicles.drop([type_col], axis=1, inplace=True)
 def rm_index(df):
df.reset_index(drop=True, inplace=True)
 df.drop([id_col], axis=1, inplace=True)
 rm_index(total2)
 rm_index(targets2)
 rm_index(vehicles)
 total2.head()
targets2.head()
submission['ConfirmedCases'] = predicted_ConfirmedCases
submission['Fatalities'] = predicted_Fatalities
submission.to_csv('submission.csv', index=False )<load_from_csv>
def scale_total(total2, scaler = None):
if scaler is None:
scaler = MinMaxScaler()
scaler.fit(total2)
 total2 = pd.DataFrame(scaler.transform(total2))
return total2, scaler
concl_df = pd.read_csv(sorted(paths)[1])
 concl_feats = ['ForecastId', 'Country_Region', 'Date']
conclusion = pd.concat([concl_df[concl_feats], submission[['ConfirmedCases', 'Fatalities']]], axis=1 )<filter>
total_scaled, scaler = scale_total(total2)
 vehicles_scaled, _ = scale_total(vehicles, scaler)
 total_scaled.head()
region = 'Russia'
conclusion[conclusion['Country_Region'] == region]<set_options>
seed = None
def set_seed(s):
tf.random.set_seed(seed)
 return s
seed = set_seed(42 )
plt.style.use('fivethirtyeight')
 le = preprocessing.LabelEncoder()
warnings.filterwarnings('ignore' )<import_modules>
class CorrLoss(tf.keras.losses.Loss):
def __init__(self, mu, sigma, moving_mean, moving_variance, *args, **kwargs):
super(CorrLoss, self ).__init__(*args, **kwargs)
 self.mu = mu
self.b = sigma * moving_variance
self.moving_mean = moving_mean
def __call__(self, y_true, y_pred, *args, **kwargs):
a = tf.reduce_mean(( y_true - self.mu)*(y_pred - self.moving_mean), axis = 0)
 result = tf.math.divide(a, self.b)
 result = tf.math.abs(1 - result)
 return tf.reduce_mean(result)
 def zero_loss(y_true, y_pred):
return 0
def create_corr_model(num_inputs, num_outputs, mu, sigma):
in_layer = L.Input(num_inputs)
 base_layer = in_layer
hidden = L.Dense(1024, use_bias = False )(base_layer)
 hidden = L.BatchNormalization()(hidden)
 hidden = L.Activation('tanh' )(hidden)
 out_layer = L.Dense(num_outputs, name='out', use_bias = False )(hidden)
 hidden = L.Dense(1024, use_bias = False )(base_layer)
 hidden = L.BatchNormalization()(hidden)
 hidden = L.Activation('tanh' )(hidden)
 out_layer += L.Dense(num_outputs, name='out1', use_bias = False )(hidden)
 out_layer = L.Activation('sigmoid', name='final' )(out_layer)
 bn = L.BatchNormalization(name = 'bn')
 out2 = bn(out_layer)
 moving_mean = bn.variables[2]
moving_variance = bn.variables[3]
model = Model(in_layer, [out_layer, out2])
 model.compile(optimizer=tf.keras.optimizers.Adam(0.001),
loss = [CorrLoss(mu, sigma, moving_mean, moving_variance), zero_loss])
 return model
import plotly.io as pio
import plotly.express as px
import plotly.graph_objects as go 
<load_from_csv>
def do_train(X, y):
num_inputs = X.shape[1]
num_outputs = y.shape[1]
mu = np.mean(y, axis = 0)
 sigma = np.std(y, axis = 0)
 id_range = np.arange(X.shape[0])
 train_ids, val_ids= train_test_split(id_range, test_size=0.4, random_state=seed)
 checkpoint_filepath = 'corr_checkpoint.h5'
corr_checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(
 filepath=checkpoint_filepath,
metric = 'val_final_loss',
save_weights_only=True,
save_best_only=True)
 model = create_corr_model(num_inputs, num_outputs, mu, sigma)
 return model,(train_ids, val_ids )
train_df = pd.read_csv(".. /input/covid19-global-forecasting-week-4/train.csv")
 test_df = pd.read_csv(".. /input/covid19-global-forecasting-week-4/test.csv")
 submission = pd.read_csv(".. /input/covid19-global-forecasting-week-4/submission.csv" )<count_missing_values>
corr_model,(corr_train_ids, corr_val_ids)= do_train(corr_train_set, train_targets.values.astype(np.float))
display(train_df.isnull().sum() /len(train_df)*100)
 display(test_df.isnull().sum() /len(test_df)*100 )<rename_columns>
n_pca = 64
pca = PCA(n_components=n_pca)
 pca_features = pca.fit_transform(total_scaled.values)
 pca_columns = ['pca-{:03d}'.format(i)for i in range(n_pca)]
train_df.rename(columns={'Province_State':'State','Country_Region':'Country'}, inplace=True)
 test_df.rename(columns={'Province_State':'State','Country_Region':'Country'}, inplace=True )<compute_test_metric>
def missings(state, country):
return country if pd.isna(state)== True else state<feature_engineering>
new_total = pd.DataFrame(total_proc, columns = total2.columns)
 added_features = pca_features
added_columns = pca_columns
new_total = pd.concat([new_total, pd.DataFrame(added_features, columns = added_columns)], axis = 1)
 train_targets=targets2[scored_columns]
train_set = new_total.loc[:trains_without_veh-1]
test_set = new_total.loc[trains_without_veh:]
num_columns = train_set.shape[1]
num_targets = train_targets.shape[1]
print('Train data', train_set.shape)
 print('Train targets', train_targets.shape)
 print('Test set', test_set.shape )
train_df['State'] = train_df.apply(lambda x: missings(x['State'],x['Country']),axis=1)
 test_df['State'] = test_df.apply(lambda x: missings(x['State'],x['Country']),axis=1 )<count_unique_values>
def glu(act, n_units):

 return act[:, :n_units] * tf.nn.sigmoid(act[:, n_units:])
 def dense_bn_glu(input_size, num_features, dropout = 0.5):
in_layer = L.Input(input_size)
 base_layer = L.Dropout(dropout )(in_layer)
 layer = L.Dense(2 * num_features )(base_layer)
 layer = L.BatchNormalization()(layer)
 layer = glu(layer, num_features)
 return Model(in_layer, layer)
 def combine_models(model1, model2):
model2_output = model2(model1.output)
 return Model(model1.input, model2_output )
print("In our data set are {} countries and {} states.".format(train_df['Country'].nunique() ,train_df['State'].nunique()))<feature_engineering>
def create_TabNet2_model(num_columns, n_steps = 4, dropout = 0.5):
num_shared = 1
num_unique = 2
num_features = 2*num_scored
num_output_features = num_scored
num_steps = n_steps
relaxation = 1.5
input_layer = L.Input(num_columns)
 input_base = L.BatchNormalization()(input_layer)
 masked_input = input_base
output_agg = []
agg_compl_mask = 1
mask_agg = []
epsilon = 1e-6
output_mask = np.random.randint(2, size=[1, num_scored, num_steps])
 output_mask_compensation = num_steps /(np.sum(output_mask, axis=2, keepdims = True)+ 1e-6)
 output_mask = output_mask * output_mask_compensation
out_agg_compl_mask = 1
out_mask_agg = []
shared_model = dense_bn_glu(num_columns, num_features, dropout)
 for i in range(num_shared-1):
shared_model = combine_models(shared_model,
dense_bn_glu(num_features, num_features, dropout))
def feature_transformer(num_layers, num_features, num_shared_features = None):
cur_model = shared_model
if(num_shared_features is None):
num_shared_features = num_features
for i in range(num_layers):
cur_model = combine_models(cur_model,
dense_bn_glu(num_shared_features, num_features, dropout))
return cur_model
def attentive_transformer(num_features, input_data):
hidden = L.Dense(num_features )(input_data)
 hidden = L.BatchNormalization()(hidden)
 return hidden
cur = feature_transformer(num_unique, num_features )(masked_input)
 coef_features = cur[:,num_output_features:]
for i in range(num_steps):
mask = attentive_transformer(num_columns, coef_features)
 mask *= agg_compl_mask
mask = L.Activation('sigmoid' )(mask)
 mask_agg.append(tf.expand_dims(mask, axis = 2))
agg_compl_mask *=(relaxation - mask)
 masked_input = mask * input_base
cur = feature_transformer(num_unique, num_features )(masked_input)
 coef_features = cur[:,num_output_features:]
output_features = tf.expand_dims(L.Activation('sigmoid' )(cur[:,:num_output_features]), axis = 2)
 out_mask = attentive_transformer(num_scored, coef_features)
 out_mask *= out_agg_compl_mask
out_mask = L.Activation('sigmoid' )(out_mask)
 out_agg_compl_mask *=(relaxation - out_mask)
 out_mask = tf.expand_dims(out_mask, axis = 2)
 out_mask_agg.append(out_mask)
 output_agg.append(( 1.0/num_steps)*output_features)
 output = tf.concat(output_agg, axis=2)
 out_mask = tf.concat(out_mask_agg, axis = 2)
 mask_loss = L.Lambda(lambda x: x, name='mask' )(out_mask)
 out_mask_compensation = num_steps /(tf.reduce_sum(out_mask, axis=2, keepdims = True)+ epsilon)
 out_mask = out_mask_compensation*out_mask
output = out_mask * output
mask_total = tf.concat(mask_agg, axis = 2)
 sparse_val = -mask_total*tf.math.log(mask_total+epsilon)
 sparse_val = tf.reduce_sum(sparse_val, axis = 1)
 sparse_loss = L.Lambda(lambda x:tf.reduce_mean(x), name='sparse' )(sparse_val)
 output = L.Lambda(lambda x:tf.reduce_sum(x, axis = 2), name='output' )(output)
 return Model(input_layer, [output, mask_loss, sparse_loss] )
df_plot = train_df.loc[: , ['Date', 'Country', 'ConfirmedCases', 'Fatalities']].groupby(['Date', 'Country'] ).max().reset_index()
df_plot.loc[:, 'Size'] = np.power(df_plot["ConfirmedCases"]+1,0.3)-1
fig = px.scatter_geo(df_plot,
locations="Country",
locationmode = "country names",
hover_name="Country",
color="ConfirmedCases",
animation_frame="Date",
size='Size',
projection="natural earth",
title="Global Spread of Covid-19",
width=1500, height=800)
 fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = 5
fig.show() 
<merge>
def dummy_loss(y_true, y_pred):
return y_pred
base_lr = 0.01
def compile_model(model, lr = base_lr):
focal_loss = tfa.losses.SigmoidFocalCrossEntropy()
binary_loss = tf.keras.losses.BinaryCrossentropy()
model.compile(optimizer=tf.keras.optimizers.Adam(lr),
loss=[binary_loss, binary_loss, dummy_loss],
metrics={'output':focal_loss},
loss_weights=[1.0, 0.0003, 0.0000001]
)
data_leak = pd.merge(train_df,test_df, how='inner', on='Date')['Date'].unique().tolist()
data_leak.append('2020-04-01')
 data_leak.sort()
print("Both data sets contain the following dates: {}".format(data_leak))<feature_engineering>
def smooth_labels(labels, factor=0.1):
labels *=(1.0 - factor)
 labels +=(factor / labels.shape[1])
 return labels
def get_mask_loss_data(train_shape, val_shape, f=np.zeros):
return f(train_shape), f(val_shape)
 def get_sparse_loss_data(train_shape, val_shape):
return get_mask_loss_data(train_shape, val_shape, np.zeros)
 class Cycle_LR() :
def __init__(self, base_lr, cycle_start, period):
self.base_lr = base_lr
self.cycle_start = cycle_start
self.period = period
self.alpha1 = 0.3 * base_lr
self.alpha2 = 0.03 * self.alpha1
def get_lr(self, epoch, cur):
if epoch == 35:
print('Cur lr', cur)
 return self.base_lr * 0.33
if epoch > self.cycle_start:
t =(( epoch - self.cycle_start)% self.period)/ self.period
cur = self.alpha2*t + self.alpha1 *(1-t)
 print('New lr:', cur)
 return cur
def create_features(df):
df['Day_num'] = le.fit_transform(df['Date'])
 df['Date'] = pd.to_datetime(df['Date'])
 df['Day'] = df['Date'].dt.day
df['Week'] = df['Date'].dt.week
df['Month'] = df['Date'].dt.month
df['DayOfWeek'] = df['Date'].dt.dayofweek
df['Country'] = le.fit_transform(df['Country'])
 country_dict = dict(zip(le.inverse_transform(df['Country']), df['Country']))
df['State'] = le.fit_transform(df['State'])
 state_dict = dict(zip(le.inverse_transform(df['State']), df['State']))
return df, country_dict, state_dict<feature_engineering>
num_folds = 1
num_steps = 8
id_range = np.arange(train_targets.shape[0])
 target_vals = train_targets.values[:,:num_scored].astype(float)
 def train_classifier(train_set, model_filename, epochs = 150, lr = base_lr, dropout = 0.5):
for k,(train_ids, test_ids)in enumerate([(id_range,id_range)]):
classifier = create_TabNet2_model(train_set.shape[1], num_steps, dropout)
 compile_model(classifier, lr)
 checkpoint_filepath = model_filename + '_checkpoint{:02d}.h5'.format(k)
 model_checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(
 filepath=checkpoint_filepath,
metric = 'val_output_loss',
save_weights_only=True,
save_best_only=True)
 cycle_lr = Cycle_LR(lr, 70, 10)
 lr_schedule = tf.keras.callbacks.LearningRateScheduler(cycle_lr.get_lr, verbose=0)
 mask_train, mask_val = get_mask_loss_data([*(target_vals[train_ids].shape), num_steps],
[*(target_vals[test_ids].shape), num_steps], np.zeros)
 sparse_train, sparse_val = get_sparse_loss_data([target_vals[train_ids].shape[0], 1], [target_vals[test_ids].shape[0], 1])
 train_true_vals = [smooth_labels(target_vals[train_ids])]
val_true_vals = [target_vals[test_ids]]
train_true_vals.append(mask_train)
 val_true_vals.append(mask_val)
 train_true_vals.append(sparse_train)
 val_true_vals.append(sparse_val)
 sample_weights = train_nums2[train_ids]
classifier.fit(train_set[train_ids],
train_true_vals,
sample_weight = 8.0 / sample_weights,
validation_data=(train_set[test_ids], val_true_vals),
callbacks=[model_checkpoint_callback, lr_schedule],
epochs=epochs, batch_size=256)
 return classifier
df_all, country_dict, state_dict = create_features(df_all )<prepare_x_and_y>
c_model_filename = 'tabnet_classifier'
corr_train_ids, corr_val_ids = train_test_split(id_range, test_size=0.4, random_state=seed + 1)
 c_model = train_classifier(train_set.values, c_model_filename, 80, lr = 0.03, dropout = 0.5 )
def train_test_split_extend(df,d,day,filter_col_confirmed,filter_col_fatalities):
df=df.loc[df['Day_num'] >= day]
df_train = df.loc[df['Day_num'] < d]
X_train = df_train
Y_train_1 = df_train['ConfirmedCases']
Y_train_2 = df_train['Fatalities']
X_train_1 = X_train.drop(columns=filter_col_fatalities ).drop(columns='ConfirmedCases')
 X_train_2 = X_train.drop(columns=filter_col_confirmed ).drop(columns='Fatalities')
 df_test = df.loc[df['Day_num'] == d]
x_test = df_test
x_test_1 = x_test.drop(columns=filter_col_fatalities ).drop(columns='ConfirmedCases')
 x_test_2 = x_test.drop(columns=filter_col_confirmed ).drop(columns='Fatalities')
 x_test.drop(['ConfirmedCases', 'Fatalities'], axis=1, inplace=True)
 X_train_1.drop('Id', inplace=True, errors='ignore', axis=1)
 X_train_1.drop('ForecastId', inplace=True, errors='ignore', axis=1)
 X_train_2.drop('Id', inplace=True, errors='ignore', axis=1)
 X_train_2.drop('ForecastId', inplace=True, errors='ignore', axis=1)
 x_test_1.drop('Id', inplace=True, errors='ignore', axis=1)
 x_test_1.drop('ForecastId', inplace=True, errors='ignore', axis=1)
 x_test_2.drop('Id', inplace=True, errors='ignore', axis=1)
 x_test_2.drop('ForecastId', inplace=True, errors='ignore', axis=1)
 return X_train_1, X_train_2, Y_train_1, Y_train_2, x_test_1, x_test_2<train_model>
def make_prediction(test_set):
results_c = []
results_g = []
for k in range(num_folds):
c_model.load_weights(c_model_filename + '_checkpoint{:02d}.h5'.format(k))
results_c.append(c_model.predict(test_set)[0])
 result = np.mean(results_c, axis = 0)
 return result
def lin_reg(X_train, Y_train, x_test):
regr = linear_model.LinearRegression()
regr.fit(X_train, Y_train)
 pred = regr.predict(x_test)
 return regr, pred<drop_column>
sample_submission = pd.read_csv(data_folder + '/sample_submission.csv')
 sample_submission.shape
def country_calculation(df_all,country,date,day):
df_country = df_all.copy()
df_country = df_country.loc[df_country['Date'] >= date]
df_country = df_country.loc[df_country['Country'] == country_dict[country]]
features = ['Id', 'State', 'Country','ConfirmedCases', 'Fatalities', 'Day_num']
df_country = df_country[features]
df_country = lag_feature(df_country, 'ConfirmedCases',range(1, 40))
df_country = lag_feature(df_country, 'Fatalities', range(1,20))
filter_col_confirmed = [col for col in df_country if col.startswith('Confirmed')]
filter_col_fatalities= [col for col in df_country if col.startswith('Fataliti')]
filter_col = np.append(filter_col_confirmed, filter_col_fatalities)
 df_country[filter_col] = df_country[filter_col].apply(lambda x: np.log1p(x))
df_country.replace([np.inf, -np.inf], 0, inplace=True)
 df_country.fillna(0, inplace=True)
 start = df_country[df_country['Id']==-999].Day_num.min()
end = df_country[df_country['Id']==-999].Day_num.max()
for d in range(start,end+1):
X_train_1, X_train_2, Y_train_1, Y_train_2, x_test_1, x_test_2 = train_test_split_extend(df_country,d,day,filter_col_confirmed,filter_col_fatalities)
 regr_1, pred_1 = lin_reg(X_train_1, Y_train_1, x_test_1)
 df_country.loc[(df_country['Day_num'] == d)&(df_country['Country'] == country_dict[country]), 'ConfirmedCases'] = pred_1[0]
regr_2, pred_2 = lin_reg(X_train_2, Y_train_2, x_test_2)
 df_country.loc[(df_country['Day_num'] == d)&(df_country['Country'] == country_dict[country]), 'Fatalities'] = pred_2[0]
df_country = lag_feature(df_country, 'ConfirmedCases',range(1, 40))
df_country = lag_feature(df_country, 'Fatalities', range(1,20))
df_country.replace([np.inf, -np.inf], 0, inplace=True)
 df_country.fillna(0, inplace=True)
 print("Calculation done.")
 return df_country<drop_column>
submission_no_veh = ~vehicles_mask[n_train:]
sample_submission.loc[:, scored_columns]=0
results = make_prediction(test_set)
 sample_submission.loc[submission_no_veh, scored_columns]=results
sample_submission.head()
<data_type_conversions><EOS> 
sample_submission.to_csv('submission.csv', index=False )