Kaggle competition: COVID19 Global Forecasting (Week 1)
train_df = pd.read_csv('.. /input/Kannada-MNIST/train.csv')
 test_df = pd.read_csv('.. /input/Kannada-MNIST/test.csv')
 dig_df = pd.read_csv('.. /input/Kannada-MNIST/Dig-MNIST.csv')
 print(train_df.shape, test_df.shape, dig_df.shape )<count_values>
train = pd.read_csv("/kaggle/input/covid19-global-forecasting-week-1/train.csv")
 test = pd.read_csv("/kaggle/input/covid19-global-forecasting-week-1/test.csv" )
train_df['label'].value_counts().sort_index()<count_values>
train = train.drop(["Province/State"], axis = "columns" )
dig_df['label'].value_counts().sort_index()<prepare_x_and_y>
train["Lat"] = train["Lat"].fillna(12.521)
 train["Long"] = train["Long"].fillna(69.968)
 train["Date"] = train["Date"].apply(lambda x: x.replace("-",""))
train["Date"] = train["Date"].astype(int )
X = train_df.drop(['label'], axis=1 ).values
Y = train_df['label']
X_test = test_df.drop(['id'], axis=1 ).values
X_dig = dig_df.drop(['label'], axis=1 ).values
Y_dig = dig_df['label']
print(X.shape, Y.shape, X_test.shape)
 print(X_dig.shape, Y_dig.shape )<split>
test = test.drop(["Province/State"], axis = "columns")
 test["Date"] = test["Date"].apply(lambda x: x.replace("-", ""))
test["Date"] = test["Date"].astype(int)
 test["Lat"] = test["Lat"].fillna(12.521)
 test["Long"] = test["Long"].fillna(69.968 )
X_train, X_dev, Y_train, Y_dev = train_test_split(X, Y, test_size=0.1 )<categorify>
x = train[["Lat", "Long", "Date"]]
y = train[["ConfirmedCases", "Fatalities"]]
n_x = 28
train_img = X_train.reshape(( -1, n_x, n_x, 1)).astype('float32')/255.
 dev_img = X_dev.reshape(( -1, n_x, n_x, 1)).astype('float32')/255.
 test_img = X_test.reshape(( -1, n_x, n_x, 1)).astype('float32')/255.
 dig_img = X_dig.reshape(( -1, n_x, n_x, 1)).astype('float32')/255.
 print(train_img.shape, dev_img.shape, test_img.shape, dig_img.shape)
 train_labels = to_categorical(Y_train)
 dev_labels = to_categorical(Y_dev)
 dig_labels = to_categorical(Y_dig)
 print(train_labels.shape, dev_labels.shape, dig_labels.shape)
 print(Y_dig[8], dig_labels[8])
 plt.figure(figsize=(1,1))
plt.imshow(X_dig[8].reshape(( 28,28)) ,cmap=plt.cm.binary)
 plt.show()<choose_model_class>
model1 = ExtraTreesClassifier()
model1.fit(x ,y["ConfirmedCases"])
model = models.Sequential()
model.add(layers.Conv2D(32, kernel_size=3, padding='same', activation='relu', input_shape=(28, 28, 1)))
 model.add(layers.Conv2D(32, kernel_size=3, padding='same', activation='relu'))
model.add(layers.BatchNormalization(momentum=0.15))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
 model.add(layers.Conv2D(32, kernel_size=3, padding='same', activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Conv2D(64, kernel_size=3, padding='same', activation='relu'))
model.add(layers.Conv2D(64, kernel_size=3, padding='same', activation='relu'))
model.add(layers.BatchNormalization(momentum=0.15))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
 model.add(layers.Conv2D(64, kernel_size=5, padding='same', activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Conv2D(128, kernel_size=3, padding='same', activation='relu'))
model.add(layers.Conv2D(128, kernel_size=3, padding='same', activation='relu'))
model.add(layers.BatchNormalization(momentum=0.15))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
 model.add(layers.Conv2D(128, kernel_size=5, padding='same', activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Flatten())
 model.add(layers.Dense(128, activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(10, activation='softmax'))
model.summary()<choose_model_class>
model4 = ExtraTreesClassifier()
model4.fit(x ,y["Fatalities"])
es = EarlyStopping(monitor='val_loss', verbose=2, patience=10)
 initial_learningrate=2e-3
model.compile(optimizer=RMSprop(lr=initial_learningrate), loss='categorical_crossentropy', metrics=['accuracy'] )<init_hyperparams>
test_x = test[["Lat", "Long", "Date"]]
cases_predict = model1.predict(test_x)
 fat_predict = model4.predict(test_x)
 ConfirmedCases = pd.DataFrame(cases_predict)
 Fatalities = pd.DataFrame(fat_predict)
 test = pd.concat([test, ConfirmedCases, Fatalities], axis = "columns" )
learning_rate_reduction = ReduceLROnPlateau(monitor='val_accuracy',patience=10,factor=0.6,min_lr=0.00001, verbose=2)
 def lr_decay(epoch):
return initial_learningrate * 0.99 ** epoch<train_model>
test = test.drop(["Country/Region", "Lat", "Long", "Date"], axis = "columns")
 test.columns = ["ForecastId", "ConfirmedCases", "Fatalities"]
epochs = 50
batch_size = 64
history = model.fit_generator(data_augment.flow(train_img, train_labels, batch_size=batch_size),
epochs=epochs, steps_per_epoch=train_img.shape[0]//batch_size,
validation_data=(dev_img, dev_labels), callbacks=[learning_rate_reduction,LearningRateScheduler(lr_decay),es,checkpoint])
 model.load_weights('BWeight.md5' )<compute_test_metric>
test.to_csv("submission.csv", index = False )