Kaggle competition: COVID19 Global Forecasting (Week 1)
x = x.astype('float32')
 x/=255.0<categorify>
train = pd.read_csv('.. /input/covid19-global-forecasting-week-1/train.csv')
 test = pd.read_csv('.. /input/covid19-global-forecasting-week-1/test.csv')
 submission = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-1/submission.csv')
df_train_y=to_categorical(df_train_y)
 df_train_y.shape<init_hyperparams>
%matplotlib inline
sns.set()
initial_learning_rate=0.001
def exp_decay() :
lr_schedule = ExponentialDecay(
 initial_learning_rate,
decay_steps=100000,
decay_rate=0.96,
staircase=True)
 return lr_schedule<choose_model_class>
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_squared_log_error
from sklearn.preprocessing import LabelEncoder
def early_stopping() :
return EarlyStopping(monitor="val_loss",patience=10,verbose=1 )<choose_model_class>
train['month'] = train['Date'].str.extract(r'[0-9]+[-]([0-9]+)[-]')
 train['day'] = train['Date'].str.extract(r'[0-9]+[-][0-9]+[-]([0-9]+)')
 train = train.drop('Date', axis = 1)
 test['month'] = test['Date'].str.extract(r'[0-9]+[-]([0-9]+)[-]')
 test['day'] = test['Date'].str.extract(r'[0-9]+[-][0-9]+[-]([0-9]+)')
 test = test.drop('Date', axis = 1)
def reduce_lr_platue() :
return ReduceLROnPlateau(
 monitor='val_loss', factor=0.1, patience=5, verbose=1,
)<split>
province = LabelEncoder()
train['Province/State'] = train['Province/State'].fillna('N')
 test['Province/State'] = test['Province/State'].fillna('N')
 province.fit(train['Province/State'].unique())
 train['Province/State'] = province.transform(train['Province/State'])
 test['Province/State'] = province.transform(test['Province/State'])
 country = LabelEncoder()
country.fit(train['Country/Region'])
 train['Country/Region'] = country.transform(train['Country/Region'])
 test['Country/Region'] = country.transform(test['Country/Region'])
seed=7
np.random.seed(seed)
 X_train, X_test, y_train, y_test = train_test_split(x, df_train_y, test_size=0.10, random_state=seed, shuffle=True )<choose_model_class>
X = train.drop(['Id', 'ConfirmedCases', 'Fatalities'], axis = 1)
 y1 = train.ConfirmedCases
y2 = train.Fatalities
test = test.drop('ForecastId', axis = 1)
 x1_tr, x1_vld, y1_tr, y1_vld = train_test_split(X, y1, test_size = 0.2, random_state = 200)
 x2_tr, x2_vld, y2_tr, y2_vld = train_test_split(X, y2, test_size = 0.2, random_state = 200)
inp_layer = Input(shape=(image_x, image_y, 1))
conv_1=Conv2D(64, kernel_size=(1, 1), padding='same', activation='relu' )(inp_layer)
 max_1=MaxPooling2D(2,2 )(conv_1)
 conv_2=Conv2D(64, kernel_size=(2, 2), padding='same', activation='relu' )(inp_layer)
 max_2=MaxPooling2D(2,2 )(conv_2)
 conv_3=Conv2D(64, kernel_size=(3, 3), padding='same', activation='relu' )(inp_layer)
 max_3=MaxPooling2D(2,2 )(conv_3)
 merged = maximum([max_1, max_2, max_3])
 bn=BatchNormalization()(merged)
 dr=Dropout(0.20 )(bn)
 conv_1=Conv2D(128, kernel_size=(1, 1), padding='same', activation='relu' )(dr)
 max_1=MaxPooling2D(2,2 )(conv_1)
 conv_2=Conv2D(128, kernel_size=(2, 2), padding='same', activation='relu' )(dr)
 max_2=MaxPooling2D(2,2 )(conv_2)
 conv_3=Conv2D(128, kernel_size=(3, 3), padding='same', activation='relu' )(dr)
 max_3=MaxPooling2D(2,2 )(conv_3)
 merged = maximum([max_1, max_2, max_3])
 bn=BatchNormalization()(merged)
 dr=Dropout(0.20 )(bn)
 model= Model(inp_layer, dr)
 model_cnn2 = Sequential()
model_cnn2.add(model)
 model_cnn2.add(Conv2D(256, kernel_size=3, activation='relu'))
model_cnn2.add(BatchNormalization())
 model_cnn2.add(Flatten())
 model_cnn2.add(Dropout(0.25))
model_cnn2.add(Dense(512,activation='relu'))
model_cnn2.add(BatchNormalization())
 model_cnn2.add(Dropout(0.20))
model_cnn2.add(Dense(64,activation='relu'))
model_cnn2.add(BatchNormalization())
 model_cnn2.add(Dropout(0.10))
model_cnn2.add(Dense(10,activation='softmax'))
model_cnn2.summary()
optimizer = RMSprop(lr=0.001)
 model_cnn2.compile(loss='categorical_crossentropy',metrics="accuracy"
, optimizer=optimizer )<choose_model_class>
tr1 = DecisionTreeRegressor()
tr2 = DecisionTreeRegressor()
tr1.fit(x1_tr, y1_tr)
 tr2.fit(x2_tr, y2_tr )
<train_model>
tr1_pred = tr1.predict(x1_vld)
 print('tr1 score : ', np.sqrt(mean_squared_log_error(y1_vld, tr1_pred)))
 tr2_pred = tr2.predict(x2_vld)
 print('tr2 score : ', np.sqrt(mean_squared_log_error(y2_vld, tr2_pred)) )
model_output_5 = model_cnn2.fit(X_train,y_train,epochs=40,batch_size=128,validation_data=(X_test,y_test),callbacks=[reduce_lr_platue() ,early_stopping() ] )<predict_on_test>
confirmed_pred = tr1.predict(test)
 fatalities_pred = tr2.predict(test )
<prepare_output><EOS> 
submission['ConfirmedCases'] = confirmed_pred
submission['Fatalities'] = fatalities_pred
submission.to_csv('submission.csv', index=False)