Kaggle competition: COVID19 Global Forecasting (Week 1)
model.evaluate(X_val,y_val )<compute_train_metric>
sns.set()
y_val_predicted = model.predict_classes(X_val)
 y_val_actual=np.argmax(y_val, axis=-1)
 cm = confusion_matrix(y_val_actual, y_val_predicted )<predict_on_test>
train = pd.read_csv('.. /input/covid19-global-forecasting-week-1/train.csv')
result = model.predict_classes(X_test )<prepare_output>
train_confm_date=train.groupby('Date')['ConfirmedCases','Fatalities'].sum()
sub_df = test[['id']]
sub_df['label'] = result<save_to_csv>
train_confirm_country=train.groupby('Country/Region')['ConfirmedCases','Fatalities'].sum().reset_index().sort_values('ConfirmedCases',ascending=False )
sub_df.to_csv('submission.csv',index=False )<import_modules>
train_confirm_country['Fatality rate in %']=train_confirm_country['Fatalities']/train_confirm_country['ConfirmedCases']
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing import image
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D, BatchNormalization
from tensorflow.keras.callbacks import LearningRateScheduler, EarlyStopping, ReduceLROnPlateau
from sklearn.metrics import accuracy_score<load_from_csv>
train_confirm_country.sort_values('Fatality rate in %', ascending=False ).head(10 )
train_dataset = pd.read_csv("/kaggle/input/Kannada-MNIST/train.csv")
 test_dataset = pd.read_csv("/kaggle/input/Kannada-MNIST/test.csv" )<data_type_conversions>
test = pd.read_csv('.. /input/covid19-global-forecasting-week-1/test.csv')
 test.head()
X_train = train_dataset.iloc[:, 1:].values.astype("float32")
 Y_train = train_dataset.iloc[:, 0].values.astype("int32")
 X_test = test_dataset.iloc[:, 1:].values.astype("float32")
 NumberID = test_dataset.iloc[:, 0].values.astype("float32" )<feature_engineering>
train.drop(['Province/State','Country/Region'],axis=1,inplace=True )
X_train /= 255.0
X_test /= 255.0<categorify>
train["Date"] = train["Date"].apply(lambda x: x.replace("-",""))
train['Date']=train['Date'].astype(int)
 train.info()
Y_train = to_categorical(Y_train, num_classes = 10 )<split>
test["Date"] = test["Date"].apply(lambda x: x.replace("-",""))
test["Date"] = test["Date"].astype(int)
 test.info()
X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.1, random_state = 0 )<define_search_space>
X_train=train.drop(['Id','ConfirmedCases','Fatalities'],axis=1)
 y_confrm=train[['ConfirmedCases']]
y_fat=train[['Fatalities']]
epochs = 50
batch_size = 64
input_dim =(28, 28, 1 )<choose_model_class>
X_test=test.drop('ForecastId',axis=1)
 X_test.head()
model = Sequential([
Conv2D(32,(3, 3), padding = 'same', activation = 'relu', input_shape = input_dim),
BatchNormalization() ,
Conv2D(32,(3, 3), padding = 'same', activation = 'relu'),
BatchNormalization() ,
MaxPool2D(2, 2),
Dropout(0.2),
Conv2D(64,(3, 3), padding = 'same', activation = 'relu'),
BatchNormalization() ,
Conv2D(64,(3, 3), padding = 'same', activation = 'relu'),
BatchNormalization() ,
MaxPool2D(2, 2),
Dropout(0.3),
Conv2D(128,(3, 3), padding = 'same', activation = 'relu'),
BatchNormalization() ,
Conv2D(128,(3, 3), padding = 'same', activation = 'relu'),
BatchNormalization() ,
MaxPool2D(2, 2),
Dropout(0.4),
Flatten() ,
Dense(10, activation = 'softmax')
 ] )<train_model>
rand_reg = RandomForestRegressor(random_state=42)
 rand_reg.fit(X_train,y_confrm)
 pred_grid1 = rand_reg.predict(X_test)
 pred_grid1 = pd.DataFrame(pred_grid1 ).round()
pred_grid1.columns = ["ConfirmedCases_prediction"]
pred_grid1.head()
datagen = ImageDataGenerator(rotation_range = 10,
zoom_range = 0.1,
width_shift_range = 0.1,
height_shift_range = 0.1,
horizontal_flip = False,
vertical_flip = False)
 datagen.fit(X_train )<choose_model_class>
rand_reg.fit(X_train,y_fat)
 pred_grid2 = rand_reg.predict(X_test)
 pred_grid2 = pd.DataFrame(pred_grid2 ).round()
pred_grid2.columns = ["Fatality_prediction"]
pred_grid2.head()
early_stopping = EarlyStopping(monitor = 'val_acc',
patience = 10,
verbose = 1,
mode = 'auto',
restore_best_weights = True )<choose_model_class>
sample=pd.read_csv('.. /input/covid19-global-forecasting-week-1/submission.csv' )
learning_rate_reduction = ReduceLROnPlateau(monitor = 'val_acc',
patience = 3,
verbose = 1,
factor = 0.5,
min_lr = 0.00001 )<choose_model_class>
tree_reg=DecisionTreeRegressor(random_state=42)
 tree_reg.fit(X_train,y_confrm )
model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['acc'] )<train_model>
y_tree_conf=tree_reg.predict(X_test)
 y_tree_conf=pd.DataFrame(y_tree_conf)
 y_tree_conf.columns=['Confrmed_prediction']
y_tree_conf.head()
history = model.fit_generator(datagen.flow(X_train,Y_train, batch_size = batch_size),
epochs = epochs,
steps_per_epoch = X_train.shape[0] // batch_size,
validation_data =(X_val, Y_val),
callbacks = [learning_rate_reduction, early_stopping] )<save_to_csv>
tree_reg=DecisionTreeRegressor(random_state=42)
 tree_reg.fit(X_train,y_fat)
 y_tree_fat=tree_reg.predict(X_test)
 y_tree_fat=pd.DataFrame(y_tree_fat ).round()
y_tree_fat.columns=['fatality_prediction']
y_tree_fat.head()
preds = model.predict_classes(X_test)
 def write_preds(preds, fname):
pd.DataFrame({"id": np.arange(preds.shape[0]), "label": preds} ).to_csv(fname, index=False)
 write_preds(preds, "submission.csv" )<install_modules>
final_sub_tree=pd.concat([submission,y_tree_conf,y_tree_fat],axis=1)
 final_sub_tree.head()
!pip install --no-deps '.. /input/timm-package/timm-0.1.26-py3-none-any.whl' > /dev/null
!pip install --no-deps '.. /input/pycocotools/pycocotools-2.0-cp37-cp37m-linux_x86_64.whl' > /dev/null<import_modules>
final_sub_tree.columns=[['ForecastId','ConfirmedCases', 'Fatalities']]
final_sub_tree.head()
import effdet
from effdet import get_efficientdet_config, EfficientDet, DetBenchTrain, DetBenchEval
from effdet.efficientdet import HeadNet 
<load_pretrained>
final_sub_tree.to_csv("submission.csv",index=False )