Kaggle competition: COVID19 Global Forecasting (Week 4)
<SOS> metric: MCRMSLE Kaggle data source: covid19-global-forecasting-(week-4)<define_search_space>
import numpy as np
import pandas as pd
cutmix_rate = 0.3
gridmask_rate = 0.3
img_size = 512
nb_classes = 1
DROP_FREQ = [0,0.75,0.75]
DROP_CT = [0,8,8]
DROP_SIZE = [0,0.2,0.2]
RATE = 0; CT = 0; SIZE = 0<categorify>
directory="/kaggle/input/covid19-global-forecasting-week-4/"
v1 = pd.read_csv('/kaggle/input/covid-w4-sub-v1/submission.csv')
 v1.to_csv("v1.csv", index=False)
 v2 = pd.read_csv('/kaggle/input/lightgbm-lead-model-week-4/submission.csv')
 v2.to_csv('v2.csv', index=False)
 v3 = pd.read_csv('/kaggle/input/covid-w4-sub-v3-lightgbm/submission.csv')
 v3.to_csv('v3.csv', index=False )
def cutmix_v2(data, label, PROBABILITY = cutmix_rate):
DIM = img_size
imgs = []; labs = []
for j in range(BATCH_SIZES[fold] * REPLICAS):
P = tf.cast(tf.random.uniform([], 0, 1)<= PROBABILITY, tf.int32)
 k = tf.cast(tf.random.uniform([], 0, BATCH_SIZES[fold] * REPLICAS), tf.int32)
 x = tf.cast(tf.random.uniform([], 0, DIM), tf.int32)
 y = tf.cast(tf.random.uniform([], 0, DIM), tf.int32)
 b = tf.random.uniform([], 0, 1)
 WIDTH = tf.cast(DIM * tf.math.sqrt(1-b),tf.int32)* P
ya = tf.math.maximum(0,y-WIDTH//2)
 yb = tf.math.minimum(DIM,y+WIDTH//2)
 xa = tf.math.maximum(0,x-WIDTH//2)
 xb = tf.math.minimum(DIM,x+WIDTH//2)
 one = data['image_data'][j,ya:yb,0:xa,:]
two = data['image_data'][k,ya:yb,xa:xb,:]
three = data['image_data'][j,ya:yb,xb:DIM,:]
middle = tf.concat([one,two,three],axis=1)
 img = tf.concat([data['image_data'][j,0:ya,:,:],middle,data['image_data'][j,yb:DIM,:,:]],axis=0)
 imgs.append(img)
 a = tf.cast(WIDTH*WIDTH/DIM/DIM,tf.float32)
 lab1 = label[j,]
lab2 = label[k,]
labs.append(( 1-a)*lab1 + a*lab2)
 image2 = tf.reshape(tf.stack(imgs),(BATCH_SIZES[fold] * REPLICAS ,DIM,DIM,3))
label2 = tf.reshape(tf.stack(labs),(BATCH_SIZES[fold] * REPLICAS, nb_classes))
data['image_data'] = image2
return data,label2<normalization>
submission =(v1*0 + v2*1)/ 1
submission = submission.astype({"ForecastId": int} )
def get_mat(rotation, shear, height_zoom, width_zoom, height_shift, width_shift):
rotation = math.pi * rotation / 180.
 shear = math.pi * shear / 180.
 c1 = tf.math.cos(rotation)
 s1 = tf.math.sin(rotation)
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 rotation_matrix = tf.reshape(tf.concat([c1,s1,zero, -s1,c1,zero, zero,zero,one],axis=0),[3,3])
 c2 = tf.math.cos(shear)
 s2 = tf.math.sin(shear)
 shear_matrix = tf.reshape(tf.concat([one,s2,zero, zero,c2,zero, zero,zero,one],axis=0),[3,3])
 zoom_matrix = tf.reshape(tf.concat([one/height_zoom,zero,zero, zero,one/width_zoom,zero, zero,zero,one],axis=0),[3,3])
 shift_matrix = tf.reshape(tf.concat([one,zero,height_shift, zero,one,width_shift, zero,zero,one],axis=0),[3,3])
 return K.dot(K.dot(rotation_matrix, shear_matrix), K.dot(zoom_matrix, shift_matrix))
cfg = dict(
 transform_prob = 1.0,
rot = 180.0,
shr = 2.0,
hzoom = 8.0,
wzoom = 8.0,
hshift = 8.0,
wshift = 8.0, 
)
 def transform_shear_rot(image,cfg):
DIM = img_size
XDIM = DIM%2
rot = cfg['rot'] * tf.random.normal([1],dtype='float32')
 shr = cfg['shr'] * tf.random.normal([1],dtype='float32')
 h_zoom = 1.0 + tf.random.normal([1],dtype='float32')/cfg['hzoom']
w_zoom = 1.0 + tf.random.normal([1],dtype='float32')/cfg['wzoom']
h_shift = cfg['hshift'] * tf.random.normal([1],dtype='float32')
 w_shift = cfg['wshift'] * tf.random.normal([1],dtype='float32')
 m = get_mat(rot,shr,h_zoom,w_zoom,h_shift,w_shift)
 x = tf.repeat(tf.range(DIM//2,-DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2,DIM//2),[DIM])
 z = tf.ones([DIM*DIM],dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(m,tf.cast(idx,dtype='float32'))
idx2 = K.cast(idx2,dtype='int32')
 idx2 = K.clip(idx2,-DIM//2+XDIM+1,DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image,tf.transpose(idx3))
return tf.reshape(d,[DIM,DIM,3] )<prepare_x_and_y>
pp = [4683, 74877, 94, 1512]
for idx in range(6119,6149):
row = submission.iloc[idx]
pp[0],pp[1] = pp[0] + pp[2], pp[1] + pp[3]
submission.loc[idx,'Fatalities'] = pp[0]
submission.loc[idx,'ConfirmedCases'] = pp[1]
pp[2] = pp[2] - 1
pp[3] = pp[3] - 20
<prepare_x_and_y><EOS> 
submission.to_csv("submission.csv", index=False )