Kaggle competition: COVID19 Global Forecasting (Week 4)
<SOS> metric: MCRMSLE Kaggle data source: covid19-global-forecasting-(week-4)<save_to_csv>
week = 4
y_test, _ = get_preds_and_labels(model, test_generator)
 y_test = optR.predict(y_test, coefficients ).astype(np.uint8)
 test_df['diagnosis'] = y_test
test_df['id_code'] = test_df['id_code'].str.replace(r'.png$', '')
 test_df.to_csv('submission.csv', index=False )<set_options>
import numpy as np
import pandas as pd
import datetime
import os
import matplotlib.pyplot as plt
%matplotlib inline<load_from_csv>
train = pd.read_csv(f"/kaggle/input/covid19-global-forecasting-week-{week}/train.csv")
 train.loc[:, "geo"] = np.where(train.loc[:, "Province_State"].isna() , train.loc[:, "Country_Region"], train.loc[:, "Country_Region"] + "_" + train.loc[:, "Province_State"])
 train.loc[:, 'Date'] = pd.to_datetime(train.loc[:, 'Date'])
 train = train.loc[train.loc[:, 'Date'] > '2020-02-20', :]
train_last_date = train.Date.unique() [-1]
print(f"Dataset has training data untill : {str(train_last_date)[:10]}")
 print(f"Training dates: {len(train.Date.unique())}" )
train_df = pd.read_csv('.. /input/aptos2019-blindness-detection/train.csv')
 test_df = pd.read_csv('.. /input/aptos2019-blindness-detection/test.csv' )<define_variables>
enriched = pd.read_csv("/kaggle/input/data-prep-week3/enriched_covid_19_week_3.csv")
 enriched.loc[:, ["Country_Region", 'total_pop']].groupby('Country_Region' ).agg({'total_pop': np.mean} ).reset_index()
IMG_SIZE = 224<load_pretrained>
all_countries = train.groupby(['Date'] ).agg({'ConfirmedCases': np.sum} ).reset_index()
all_countries['sh'] = train.groupby(['Date'] ).agg({'ConfirmedCases': np.sum} ).reset_index().shift(1)['ConfirmedCases']
all_countries['sh'] =(all_countries['ConfirmedCases'] / all_countries['sh'])- 1
all_countries = all_countries.set_index("Date")
 all_countries['sh'].plot()
def load_img(path):
image = cv2.imread(path)
 return image<load_pretrained>
train_old = train.loc[train.loc[:, 'Date'] > '2020-04-01', :]
plt.imshow(preprocess_img('.. /input/aptos2019-blindness-detection/train_images/'+train_df.loc[1]['id_code']+'.png'))<feature_engineering>
test = pd.read_csv(f"/kaggle/input/covid19-global-forecasting-week-{week}/test.csv")
 test.loc[:, 'Date'] = pd.to_datetime(test.loc[:, 'Date'])
 test_first_date = test.loc[:, 'Date'].values[0]
test_last_date = test.loc[:, 'Date'].values[-1]
print(f'Test period from {str(test_first_date)[:10]} to {str(test_last_date)[:10]}' )
N = train_df.shape[0]
train = np.empty(( N, IMG_SIZE, IMG_SIZE, 3), dtype=np.float32)
 for i, image_id in enumerate(tqdm(train_df['id_code'])) :
train[i,:,:,:] = preprocess_img('.. /input/aptos2019-blindness-detection/train_images/'+image_id+'.png' )<prepare_x_and_y>
period =(np.array(test_last_date, dtype='datetime64[D]' ).astype(np.int64)- np.array(train_last_date, dtype='datetime64[D]' ).astype(np.int64))
y = np.zeros(( train_df.shape[0],5), dtype=np.int8 )<feature_engineering>
print(f"Prediction days: {(np.array(test_last_date, dtype='datetime64[D]' ).astype(np.int64)- np.array(train_last_date, dtype='datetime64[D]' ).astype(np.int64)) +1}")
 print(f"Public set: {(np.array(train_last_date, dtype='datetime64[D]' ).astype(np.int64)- np.array(test_first_date, dtype='datetime64[D]' ).astype(np.int64)) +1}")
 print(f"Full prediction set: {(np.array(test_last_date, dtype='datetime64[D]' ).astype(np.int64)- np.array(test_first_date, dtype='datetime64[D]' ).astype(np.int64)) +1}" )
for i, diagnosis in enumerate(train_df['diagnosis']):
for k in range(diagnosis+1):
y[i,k] = 1<split>
win = 10
hor = 1
X_train, X_val, y_train, y_val = train_test_split(train, y, test_size=0.15, random_state=42 )<define_variables>
train.loc[:, 'ConfirmedCases'] = train.loc[:, 'ConfirmedCases'] - train.groupby('geo')['ConfirmedCases'].shift(periods=1)
 train.loc[:, 'Fatalities'] = train.loc[:, 'Fatalities'] - train.groupby('geo')['Fatalities'].shift(periods=1)
 train = train.groupby('geo' ).tail(train.groupby('geo' ).size().values[0]-1)
 train.loc[train.loc[:, 'ConfirmedCases'] < 0, 'ConfirmedCases'] = 0.0
train.loc[train.loc[:, 'Fatalities'] < 0, 'Fatalities'] = 0.0
train
BATCH_SIZE = 32<define_variables>
%%bash
pip install pytorch_lightning
class TestSequence(tf.keras.utils.Sequence):
def __init__(self, x_set, batch_size, aug=True):
self.x = x_set
self.batch_size = batch_size
self.aug = aug
def __len__(self):
return int(np.ceil(len(self.x)/ self.batch_size))
def __getitem__(self, idx):
batch_x = self.x[idx * self.batch_size:(idx + 1)* self.batch_size]
images = np.empty(( batch_x.shape[0], IMG_SIZE, IMG_SIZE, 3), dtype=np.float32)
 for i, image_id in enumerate(batch_x):
preprocessed_img = preprocess_img('.. /input/aptos2019-blindness-detection/test_images/'+image_id+'.png')
 if self.aug:
h_flip = bool(random.getrandbits(1))
v_flip = bool(random.getrandbits(1))
rotate = random.randint(0,20)
 transform_parameters={'theta':rotate, 'flip_horizontal': h_flip, 'flip_vertical': v_flip}
preprocessed_img = tf.keras.preprocessing.image.ImageDataGenerator().apply_transform(preprocessed_img, transform_parameters)
 images[i,:,:,:] = preprocessed_img
return images<feature_engineering>
import torch.nn as nn
import torch
import torch.nn.functional as F
import pytorch_lightning as ptl
from torch import optim
from torch.utils.data import DataLoader
from collections import OrderedDict
train_data_generator = tf.keras.preprocessing.image.ImageDataGenerator(
 fill_mode='constant',
cval=0.,
horizontal_flip=True,
vertical_flip=True,
rotation_range=15,
)<define_variables>
def rmsle(predict, target):
return torch.sqrt(((torch.log(predict + 1)- torch.log(target + 1)) **2 ).mean() )
train_gen = train_data_generator.flow(X_train, y_train, batch_size=BATCH_SIZE)
 val_gen = val_data_generator.flow(X_val, y_val, batch_size=BATCH_SIZE, shuffle=False )<train_model>
class MTSFDataset(torch.utils.data.Dataset):
def __init__(self, window, horizon, set_type, tra, validation):
assert type(set_type)== type('str')
 self.window = window
self.horizon = horizon
self.tra = tra
self.validation = validation
self.set_type = set_type
if set_type == 'train':
rawdata = tra
elif set_type == 'validation':
rawdata = validation
_, self.len, self.var_num = rawdata.shape
self.sample_num = max(self.len - self.window - self.horizon + 1, 0)
 self.samples, self.labels = self.__getsamples(rawdata)
 def __getsamples(self, data):
x, y = [], []
for j in range(len(data)) :
X = torch.zeros(( self.sample_num, self.window, self.var_num))
Y = torch.zeros(( self.sample_num, 1, self.var_num))
for i in range(self.sample_num):
start = i
end = i + self.window
X[i, :, :] = torch.from_numpy(data[j, start:end, :])
 Y[i, :, :] = torch.from_numpy(data[j, end+self.horizon-1, :])
 x.append(X)
 y.append(Y)
 return(torch.cat(x), torch.cat(y))
def __len__(self):
return self.sample_num
def __getitem__(self, idx):
sample = [self.samples[idx, :, :], self.labels[idx, :, :]]
return sample
class Metrics(tf.keras.callbacks.Callback):
def __init__(self, val_data, batch_size = 20):
super().__init__()
self.validation_data = val_data
self.batch_size = batch_size
def on_train_begin(self, logs={}):
self.val_kappas = []
def on_epoch_end(self, epoch, logs={}):
X_val, y_val = self.validation_data[:2]
y_val = y_val.sum(axis=1)- 1
y_pred = self.model.predict(X_val)> 0.5
y_pred = y_pred.astype(int ).sum(axis=1)- 1
_val_kappa = metrics.cohen_kappa_score(
 y_val,
y_pred,
weights='quadratic' 
)
 self.val_kappas.append(_val_kappa)
 print(f" val_kappa: {_val_kappa:.4f}")
 if _val_kappa == max(self.val_kappas):
print("Validation Kappa has improved.Saving model.")
 self.model.save('model.h5')
 return<compute_test_metric>
class ScaledDotProductAttention(nn.Module):
def __init__(self, temperature, attn_dropout=0.1):
super().__init__()
self.temperature = temperature
self.dropout = nn.Dropout(attn_dropout)
 self.softmax = nn.Softmax(dim=2)
 def forward(self, q, k, v):
attn = torch.bmm(q, k.transpose(1, 2))
attn = attn / self.temperature
attn = self.softmax(attn)
 attn = self.dropout(attn)
 output = torch.bmm(attn, v)
 return output, attn
class MultiHeadAttention(nn.Module):
def __init__(self, n_head, d_model, d_k, d_v, dropout=0.1):
super().__init__()
self.n_head = n_head
self.d_k = d_k
self.d_v = d_v
self.w_qs = nn.Linear(d_model, n_head * d_k)
 self.w_ks = nn.Linear(d_model, n_head * d_k)
 self.w_vs = nn.Linear(d_model, n_head * d_v)
 nn.init.normal_(self.w_qs.weight, mean=0, std=np.sqrt(2.0 /(d_model + d_k)))
 nn.init.normal_(self.w_ks.weight, mean=0, std=np.sqrt(2.0 /(d_model + d_k)))
 nn.init.normal_(self.w_vs.weight, mean=0, std=np.sqrt(2.0 /(d_model + d_v)))
 self.attention = ScaledDotProductAttention(temperature=np.power(d_k, 0.5))
self.layer_norm = nn.LayerNorm(d_model)
 self.fc = nn.Linear(n_head * d_v, d_model)
 nn.init.xavier_normal_(self.fc.weight)
 self.dropout = nn.Dropout(dropout)
 def forward(self, q, k, v):
d_k, d_v, n_head = self.d_k, self.d_v, self.n_head
sz_b, len_q, _ = q.size()
sz_b, len_k, _ = k.size()
sz_b, len_v, _ = v.size()
residual = q
q = self.w_qs(q ).view(sz_b, len_q, n_head, d_k)
 k = self.w_ks(k ).view(sz_b, len_k, n_head, d_k)
 v = self.w_vs(v ).view(sz_b, len_v, n_head, d_v)
 q = q.permute(2, 0, 1, 3 ).contiguous().view(-1, len_q, d_k)
 k = k.permute(2, 0, 1, 3 ).contiguous().view(-1, len_k, d_k)
 v = v.permute(2, 0, 1, 3 ).contiguous().view(-1, len_v, d_v)
 output, attn = self.attention(q, k, v)
 output = output.view(n_head, sz_b, len_q, d_v)
 output = output.permute(1, 2, 0, 3 ).contiguous().view(sz_b, len_q, -1)
 output = self.dropout(self.fc(output))
output = self.layer_norm(output + residual)
 return output, attn
class PositionwiseFeedForward(nn.Module):
def __init__(self, d_in, d_hid, dropout=0.1):
super().__init__()
self.w_1 = nn.Conv1d(d_in, d_hid, 1)
 self.w_2 = nn.Conv1d(d_hid, d_in, 1)
 self.layer_norm = nn.LayerNorm(d_in)
 self.dropout = nn.Dropout(dropout)
 def forward(self, x):
residual = x
output = x.transpose(1, 2)
 output = self.w_2(F.relu(self.w_1(output)))
 output = output.transpose(1, 2)
 output = self.dropout(output)
 output = self.layer_norm(output + residual)
 return output
class EncoderLayer(nn.Module):
def __init__(self, d_model, d_inner, n_head, d_k, d_v, dropout=0.1):
super(EncoderLayer, self ).__init__()
self.slf_attn = MultiHeadAttention(
 n_head, d_model, d_k, d_v, dropout=dropout)
 self.pos_ffn = PositionwiseFeedForward(d_model, d_inner, dropout=dropout)
 def forward(self, enc_input):
enc_output, enc_slf_attn = self.slf_attn(
 enc_input, enc_input, enc_input)
 enc_output = self.pos_ffn(enc_output)
 return enc_output, enc_slf_attn
class DecoderLayer(nn.Module):
def __init__(self, d_model, d_inner, n_head, d_k, d_v, dropout=0.1):
super(DecoderLayer, self ).__init__()
self.slf_attn = MultiHeadAttention(n_head, d_model, d_k, d_v, dropout=dropout)
 self.enc_attn = MultiHeadAttention(n_head, d_model, d_k, d_v, dropout=dropout)
 self.pos_ffn = PositionwiseFeedForward(d_model, d_inner, dropout=dropout)
 def forward(self, dec_input, enc_output, non_pad_mask=None, slf_attn_mask=None, dec_enc_attn_mask=None):
dec_output, dec_slf_attn = self.slf_attn(
 dec_input, dec_input, dec_input, mask=slf_attn_mask)
 dec_output, dec_enc_attn = self.enc_attn(
 dec_output, enc_output, enc_output, mask=dec_enc_attn_mask)
 dec_output = self.pos_ffn(dec_output)
 return dec_output, dec_slf_attn, dec_enc_attn
class Single_Global_SelfAttn_Module(nn.Module):
def __init__(
 self,
window, n_multiv, n_kernels, w_kernel,
d_k, d_v, d_model, d_inner,
n_layers, n_head, drop_prob=0.1):

 super(Single_Global_SelfAttn_Module, self ).__init__()
self.window = window
self.w_kernel = w_kernel
self.n_multiv = n_multiv
self.d_model = d_model
self.drop_prob = drop_prob
self.conv2 = nn.Conv2d(1, n_kernels,(window, w_kernel))
self.in_linear = nn.Linear(n_kernels, d_model)
 self.out_linear = nn.Linear(d_model, n_kernels)
 self.layer_stack = nn.ModuleList([
EncoderLayer(d_model, d_inner, n_head, d_k, d_v, dropout=drop_prob)
 for _ in range(n_layers)])
 def forward(self, x, return_attns=False):
x = x.view(-1, self.w_kernel, self.window, self.n_multiv)
 x2 = F.relu(self.conv2(x))
x2 = nn.Dropout(p=self.drop_prob )(x2)
 x = torch.squeeze(x2, 2)
 x = torch.transpose(x, 1, 2)
 src_seq = self.in_linear(x)
 enc_slf_attn_list = []
enc_output = src_seq
for enc_layer in self.layer_stack:
enc_output, enc_slf_attn = enc_layer(enc_output)
 if return_attns:
enc_slf_attn_list += [enc_slf_attn]
if return_attns:
return enc_output, enc_slf_attn_list
enc_output = self.out_linear(enc_output)
 return enc_output,
class Single_Local_SelfAttn_Module(nn.Module):
def __init__(
 self,
window, local, n_multiv, n_kernels, w_kernel,
d_k, d_v, d_model, d_inner,
n_layers, n_head, drop_prob=0.1):

 super(Single_Local_SelfAttn_Module, self ).__init__()
self.window = window
self.w_kernel = w_kernel
self.n_multiv = n_multiv
self.d_model = d_model
self.drop_prob = drop_prob
self.conv1 = nn.Conv2d(1, n_kernels,(local, w_kernel))
self.pooling1 = nn.AdaptiveMaxPool2d(( 1, n_multiv))
self.in_linear = nn.Linear(n_kernels, d_model)
 self.out_linear = nn.Linear(d_model, n_kernels)
 self.layer_stack = nn.ModuleList([
EncoderLayer(d_model, d_inner, n_head, d_k, d_v, dropout=drop_prob)
 for _ in range(n_layers)])
 def forward(self, x, return_attns=False):
x = x.view(-1, self.w_kernel, self.window, self.n_multiv)
 x1 = F.relu(self.conv1(x))
x1 = self.pooling1(x1)
 x1 = nn.Dropout(p=self.drop_prob )(x1)
 x = torch.squeeze(x1, 2)
 x = torch.transpose(x, 1, 2)
 src_seq = self.in_linear(x)
 enc_slf_attn_list = []
enc_output = src_seq
for enc_layer in self.layer_stack:
enc_output, enc_slf_attn = enc_layer(enc_output)
 if return_attns:
enc_slf_attn_list += [enc_slf_attn]
if return_attns:
return enc_output, enc_slf_attn_list
enc_output = self.out_linear(enc_output)
 return enc_output,
class AR(nn.Module):
def __init__(self, window):
super(AR, self ).__init__()
self.linear = nn.Linear(window, 1)
 def forward(self, x):
x = torch.transpose(x, 1, 2)
 x = self.linear(x)
 x = torch.transpose(x, 1, 2)
 return x
class DSANet(ptl.LightningModule):
def __init__(self, tra, validation, n_multiv, batch_size=16, window=64, local=3, n_kernels=32,
drop_prob=0.1, criterion='rmsle_loss', learning_rate=0.005, horizon=14):
super(DSANet, self ).__init__()
self.batch_size = batch_size
self.window = window
self.local = local
self.n_multiv = n_multiv
self.n_kernels = n_kernels
self.w_kernel = 1
self.d_model = 512
self.d_inner = 2048
self.n_layers = 6
self.n_head = 8
self.d_k = 64
self.d_v = 64
self.drop_prob = drop_prob
self.criterion = criterion
self.learning_rate = learning_rate
self.horizon = horizon
self.tra = tra
self.validation = validation
self.__build_model()
def __build_model(self):
self.sgsf = Single_Global_SelfAttn_Module(
 window=self.window, n_multiv=self.n_multiv, n_kernels=self.n_kernels,
w_kernel=self.w_kernel, d_k=self.d_k, d_v=self.d_v, d_model=self.d_model,
d_inner=self.d_inner, n_layers=self.n_layers, n_head=self.n_head, drop_prob=self.drop_prob)
 self.slsf = Single_Local_SelfAttn_Module(
 window=self.window, local=self.local, n_multiv=self.n_multiv, n_kernels=self.n_kernels,
w_kernel=self.w_kernel, d_k=self.d_k, d_v=self.d_v, d_model=self.d_model,
d_inner=self.d_inner, n_layers=self.n_layers, n_head=self.n_head, drop_prob=self.drop_prob)
 self.ar = AR(window=self.window)
 self.W_output1 = nn.Linear(2 * self.n_kernels, 1)
 self.dropout = nn.Dropout(p=self.drop_prob)
 self.active_func = nn.Tanh()
def forward(self, x):
sgsf_output, *_ = self.sgsf(x)
 slsf_output, *_ = self.slsf(x)
 sf_output = torch.cat(( sgsf_output, slsf_output), 2)
 sf_output = self.dropout(sf_output)
 sf_output = self.W_output1(sf_output)
 sf_output = torch.transpose(sf_output, 1, 2)
 ar_output = self.ar(x)
 output = sf_output + ar_output
output[output < 0] = 0.0
return output
def loss(self, labels, predictions):
if self.criterion == 'l1_loss':
loss = F.l1_loss(predictions, labels)
 elif self.criterion == 'mse_loss':
loss = F.mse_loss(predictions, labels)
 elif self.criterion == 'rmsle_loss':
loss = rmsle(predictions, labels)
 return loss
def training_step(self, data_batch, batch_i):
x, y = data_batch
y_hat = self.forward(x)
 loss_val = self.loss(y, y_hat)
 if self.trainer.use_dp:
loss_val = loss_val.unsqueeze(0)
 output = OrderedDict({
'loss': loss_val
})
 return output
def validation_step(self, data_batch, batch_i):
x, y = data_batch
y_hat = self.forward(x)
 loss_val = self.loss(y, y_hat)
 if self.trainer.use_dp:
loss_val = loss_val.unsqueeze(0)
 output = OrderedDict({
'val_loss': loss_val,
'y': y,
'y_hat': y_hat,
})
 return output
def validation_epoch_end(self, outputs):
loss_sum = 0
for x in outputs:
loss_sum += x['val_loss'].item()
val_loss_mean = loss_sum / len(outputs)
 y = torch.cat(( [x['y'] for x in outputs]), 0)
 y_hat = torch.cat(( [x['y_hat'] for x in outputs]), 0)
 num_var = y.size(-1)
 y = y.view(-1, num_var)
 y_hat = y_hat.view(-1, num_var)
 sample_num = y.size(0)
 y_diff = y_hat - y
y_mean = torch.mean(y)
 y_translation = y - y_mean
val_rrse = torch.sqrt(torch.sum(torch.pow(y_diff, 2)))/ torch.sqrt(torch.sum(torch.pow(y_translation, 2)))
 y_m = torch.mean(y, 0, True)
 y_hat_m = torch.mean(y_hat, 0, True)
 y_d = y - y_m
y_hat_d = y_hat - y_hat_m
corr_top = torch.sum(y_d * y_hat_d, 0)
 corr_bottom = torch.sqrt(( torch.sum(torch.pow(y_d, 2), 0)* torch.sum(torch.pow(y_hat_d, 2), 0)))
 corr_inter = corr_top / corr_bottom
val_corr =(1./ num_var)* torch.sum(corr_inter)
 val_mae =(1./(sample_num * num_var)) * torch.sum(torch.abs(y_diff))
tqdm_dic = {
'val_loss': val_loss_mean,
'RRSE': val_rrse.item() ,
'CORR': val_corr.item() ,
'MAE': val_mae.item()
}
return tqdm_dic
def configure_optimizers(self):
optimizer = optim.Adam(self.parameters() , lr=self.learning_rate)
 scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=10)
 return [optimizer], [scheduler]
def __dataloader(self, train):
set_type = train
dataset = MTSFDataset(window=self.window, horizon=self.horizon,
set_type=set_type,
tra=self.tra, validation=self.validation)
 train_sampler = None
batch_size = self.batch_size
should_shuffle = train_sampler is None
loader = DataLoader(
 dataset=dataset,
batch_size=batch_size,
shuffle=should_shuffle,
sampler=train_sampler,
num_workers=4 
)
 return loader
@ptl.data_loader
def train_dataloader(self):
return self.__dataloader(train='train')
 @ptl.data_loader
def val_dataloader(self):
return self.__dataloader(train='validation' )
kappa_cb = Metrics(((X_val, y_val)) )<choose_model_class>
model_cases = DSANet(np.array([train_fatal, train_cases]), np.array([valid_fatal, valid_cases]), train_cases.shape[1], window=win,
learning_rate=0.01, horizon=hor, drop_prob=0.5, batch_size=128)
 trainer = ptl.Trainer(val_check_interval=1, max_steps=5000, gpus=1, show_progress_bar=False)
 trainer.fit(model_cases )
densenet = tf.keras.applications.DenseNet121(include_top=False, weights='.. /input/densenet121/densenet121_weights_tf_dim_ordering_tf_kernels_notop.h5', input_shape=(IMG_SIZE, IMG_SIZE, 3))<choose_model_class>
sd = torch.load(glob("/kaggle/working/lightning_logs/version_0/checkpoints/*.ckpt")[0])
 model_cases.load_state_dict(sd['state_dict'] )
model = tf.keras.Sequential([
densenet,
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(5, activation='sigmoid')
 ] )<feature_engineering>
pred_size =(np.array(test_last_date, dtype='datetime64[D]' ).astype(np.int64)- np.array(test_first_date, dtype='datetime64[D]' ).astype(np.int64)) +1
reduce_lr = tf.keras.callbacks.ReduceLROnPlateau(monitor='val_acc', factor=0.6, patience=6, verbose=1)
 class_weights = class_weight.compute_class_weight('balanced', np.unique(np.sum(y_train, axis=1)) , np.sum(y_train, axis=1))<choose_model_class>
sub = pd.read_csv(f"/kaggle/input/covid19-global-forecasting-week-{week}/submission.csv")
 sub = test.merge(res, how='left', on=['Date', 'Province_State', 'Country_Region'] ).loc[:, ["ForecastId", "ConfirmedCases", "Fatalities"]]
sub['Fatalities'] = np.array(sub['Fatalities'], dtype=np.int)
 sub["ConfirmedCases"] = np.array(sub["ConfirmedCases"], dtype=np.int)
 sub
optimizer = tf.keras.optimizers.Adam(lr=5e-5 )<define_variables>
sub.to_csv("submission.csv", index=False )