Kaggle competition: COVID19 Global Forecasting (Week 3)
<SOS> metric: MCRMSLE Kaggle data source: covid19-global-forecasting-week-3<train_model>
folder = '/kaggle/input/covid19-global-forecasting-week-3/'
submission = pd.read_csv(folder+'submission.csv',index_col=0)
 test = pd.read_csv(folder+'test.csv',index_col=0)
 test['Date'] = pd.to_datetime(test['Date'],format='%Y-%m-%d')
 test['Province_State'] = test['Province_State'].fillna(value='NaN')
 data_cases = format_kaggle(folder,'ConfirmedCases')
 data_deaths = format_kaggle(folder,'Fatalities' )
lgbm = LgbModel(data, test, target, features, categoricals=categoricals, n_splits=10,
cv_method="StratifiedKFold", group=None, task="classification", scaler=None, verbose=True )<create_dataframe>
params_cases = fit_all(data_cases,plot=True,ylabel='Confirmed Cases',p0=1e2,prior=(8,500))
params_cases.to_csv('params_cases.csv' )
catb = CatbModel(data, test, target, features, categoricals=categoricals, n_splits=10,
cv_method="StratifiedKFold", group=None, task="classification", scaler=None, verbose=True )<load_from_csv>
params_deaths = fit_all(data_deaths,plot=True,ylabel='Fatalities',p0=10,prior=(8,200))
params_deaths.to_csv('params_deaths.csv' )
<save_to_csv><EOS> 
for item in submission.index:
country = test.loc[item,'Country_Region']
province = test.loc[item,'Province_State']
t_abs = test.loc[item,'Date']
t =(t_abs-tref)/pd.to_timedelta(1,unit='days')
 th, logK, sigma = params_cases[['th','logK','sigma']].loc[country,province]
if not np.isnan(th):
tau =(t-th)/(np.sqrt(2)*sigma)
 submission.loc[item,'ConfirmedCases'] = np.exp(logK)*(1+erf(tau)) /2
else:
if t_abs in data_cases.index:
submission.loc[item,'ConfirmedCases'] = data_cases[country,province].loc[t_abs]
else:
submission.loc[item,'ConfirmedCases'] = data_cases[country,province].max()
th, logK, sigma = params_deaths[['th','logK','sigma']].loc[country,province]
if not np.isnan(th):
tau =(t-th)/(np.sqrt(2)*sigma)
 submission.loc[item,'Fatalities'] = np.exp(logK)*(1+erf(tau)) /2
else:
if t_abs in data_deaths.index:
submission.loc[item,'Fatalities'] = data_deaths[country,province].loc[t_abs]
else:
submission.loc[item,'Fatalities'] = data_deaths[country,province].max()
submission.to_csv('submission.csv' )