Kaggle competition: COVID19 Global Forecasting (Week 4)
test = test.merge(test_df, right_index=True, left_on='groupId' )<save_to_csv>
train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv',parse_dates = ['Date'])
 test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv',parse_dates = ['Date'])
 train['Country_State']=train.Country_Region+train.Province_State.fillna('')
 test['Country_State']=test.Country_Region+test.Province_State.fillna('')
 train.head()
test[['Id', 'winPlacePerc']].to_csv("submission.csv", index=False )<load_from_csv>
test_df = test[['ForecastId','Country_State']]
df_cal = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/calendar.csv')
 df_eval = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/sales_train_evaluation.csv')
 df_price = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/sell_prices.csv')
 df_sample_output = pd.read_csv('/kaggle/input/m5-forecasting-accuracy/sample_submission.csv' )<feature_engineering>
countriesorstates = train_df["Country_State"].unique()
print(len(countriesorstates))
holiday = ['NewYear', 'OrthodoxChristmas', 'MartinLutherKingDay', 'SuperBowl', 'PresidentsDay', 'StPatricksDay', 'Easter', 'Cinco De Mayo', 'IndependenceDay', 'EidAlAdha', 'Thanksgiving', 'Christmas']
weekend = ['Saturday', 'Sunday']
df_cal['is_holiday_1'] = df_cal['event_name_1'].apply(lambda x : 1 if x in holiday else 0)
 df_cal['is_holiday_2'] = df_cal['event_name_1'].apply(lambda x : 1 if x in holiday else 0)
 df_cal['is_holiday'] = df_cal[['is_holiday_1','is_holiday_2']].max(axis=1)
 df_cal['is_weekend'] = df_cal['weekday'].apply(lambda x : 1 if x in weekend else 0 )<drop_column>
sub = pd.DataFrame({'ForecastId': [], 'ConfirmedCases': [], 'Fatalities': []})
 strt = '2020-04-02'
end = '2020-05-14'
for value in countriesorstates:
random.seed(0)
 train_model_cc = Prophet(seasonality_mode = 'multiplicative',changepoint_prior_scale = 30, interval_width=0.95)
 train_model_ft = Prophet(seasonality_mode = 'multiplicative',changepoint_prior_scale = 30, interval_width=0.95)
 train_temp = train_df.loc[train_df["Country_State"] == value]
test_temp = test_df.loc[test_df["Country_State"] == value]
train_temp_cc = train_temp[['Date','ConfirmedCases']]
train_temp_cc = train_temp_cc.sort_values(by = ['Date'])
 train_temp_cc = train_temp_cc.rename(columns = {'Date':'ds','ConfirmedCases':'y'})
 train_temp_ft = train_temp[['Date','Fatalities']]
train_temp_ft = train_temp_ft.sort_values(by = ['Date'])
 train_temp_ft = train_temp_ft.rename(columns = {'Date':'ds','Fatalities':'y'})
 train_model_cc.fit(train_temp_cc)
 train_forecast_cc = train_model_cc.make_future_dataframe(periods=43, freq='D',include_history = True)
 train_forecast_cc = train_model_cc.predict(train_forecast_cc)
 reg_cc = train_forecast_cc[['ds','yhat']]
test_cc = reg_cc[(reg_cc['ds']>=strt)&(reg_cc['ds']<=end)]
test_cc = test_cc.yhat.values
train_model_ft.fit(train_temp_ft)
 train_forecast_ft = train_model_ft.make_future_dataframe(periods=43, freq='D',include_history = True)
 train_forecast_ft = train_model_ft.predict(train_forecast_ft)
 reg_ft = train_forecast_ft[['ds','yhat']]
test_ft = reg_ft[(reg_ft['ds']>=strt)&(reg_ft['ds']<=end)]
test_ft = test_ft.yhat.values
test_cc = test_cc.flatten()
test_ft = test_ft.flatten()
sub_temp = pd.DataFrame({'ForecastId': test_temp["ForecastId"].loc[test_temp["Country_State"] == value],
'ConfirmedCases': test_cc, 'Fatalities': test_ft})
 sub = pd.concat([sub, sub_temp], axis = 0 )
df_cal = df_cal.drop(['weekday', 'wday', 'month', 'year', 'event_name_1', 'event_type_1', 'event_name_2', 'event_type_2'], axis='columns' )<drop_column>
sub.ForecastId = sub.ForecastId.astype('int')
 for i in range(len(sub)) :
sub["ConfirmedCases"][i] = int(round(sub["ConfirmedCases"][i]))
sub["Fatalities"][i] = int(round(sub["Fatalities"][i]))
sub.to_csv("submission.csv", index = False )