Kaggle competition: OpenVaccine: COVID-19 mRNA Vaccine Degradation Prediction
<SOS> metric: MWCRMSE Kaggle data source: stanford-covid-vaccine<find_best_model_class>
import numpy as np
import pandas as pd
xout = pd.DataFrame({'ForecastId': [], 'ConfirmedCases': [], 'Fatalities': []})
 y1_xTrain = X_xTrain.loc[:, 'ConfirmedCases']
y2_xTrain = X_xTrain.loc[:, 'Fatalities']
X_xTest_CS_Id = X_xTest.loc[:, 'ForecastId']
X_xtrain_Cs=X_xTrain.drop(columns=['Id','ConfirmedCases','Fatalities'])
 X_xtest_Cs=X_xTest.drop(columns=['ForecastId'])
 xmodel1 = DecisionTreeRegressor()
xmodel1.fit(X_xtrain_Cs, y1_xTrain)
 y1_xpred = xmodel1.predict(X_xtest_Cs)
 xmodel2 = DecisionTreeRegressor()
xmodel2.fit(X_xtrain_Cs, y2_xTrain)
 y2_xpred = xmodel2.predict(X_xtest_Cs )<create_dataframe>
df_test = pd.read_json('.. /input/stanford-covid-vaccine/test.json', lines=True)
 df = pd.read_csv('.. /input/worst-submission/ensemble52.csv' )
xdata = pd.DataFrame({'ForecastId': X_xTest_CS_Id, 'ConfirmedCases': y1_xpred, 'Fatalities': y2_xpred})
 xout = pd.concat([xout, xdata], axis=0 )<save_to_csv>
sequences = list(set(df_test[df_test.seq_length == 130].id))
sequences.sort()
xout.ForecastId = xout.ForecastId.astype('int')
 xout.ConfirmedCases = xout.ConfirmedCases.astype('int')
 xout.Fatalities = xout.Fatalities.astype('int')
 xout.tail()
xout.to_csv('submission.csv', index=False )<load_from_csv>
df.loc[df.id_seqpos.str.startswith('id_fe9353d84'), 'reactivity'] = 100
pd.set_option('display.max_columns', 200)
 pd.set_option('display.max_rows', 200)
 pd.set_option('display.max_columns', 100)
 train=pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
 test=pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
 submission=pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv')
 train['Province_State'].fillna('NoState', inplace=True)
 train['Location'] = train['Country_Region'].str.cat(train['Province_State'],sep="_")
 test['Province_State'].fillna('NoState', inplace=True)
 test['Location'] = test['Country_Region'].str.cat(test['Province_State'],sep="_")
 len(test['Location'].unique())
 test_d=test[test["Date"] > max(train['Date'])]
location=train['Location'].unique()
print(len(location))
appended_data3 =pd.DataFrame()
for location in location:
all_df = train[train['Location']==location].groupby('Date')['ConfirmedCases'].sum().reset_index()
df_prophet = all_df.loc[:,["Date", 'ConfirmedCases']]
df_prophet.columns = ['ds','y']
m_d = Prophet(yearly_seasonality= True,
weekly_seasonality = True,
daily_seasonality = True,
seasonality_mode = 'additive')
 m_d.fit(df_prophet)
 future_d = m_d.make_future_dataframe(periods=35)
 fcst_daily = m_d.predict(future_d)
 fcst_daily['Loca']=location
data=fcst_daily[['ds','Loca', 'yhat']]
appended_data3=appended_data3.append(data,ignore_index=True)
 appended_data3.rename(columns={'yhat':'ConfirmedCases'}, inplace=True)
 appended_data3.rename(columns={'Loca':'Location'}, inplace=True)
 appended_data3['Location'].str.strip()
appended_data3['Date']=appended_data3['ds'].dt.strftime('%Y-%m-%d')
 sub3=test.merge(appended_data3, on=('Date','Location'),how='left' ).reset_index(drop=True)
 appended_data3.head
tr_data=copy.deepcopy(train)
 locat=tr_data['Location'].unique()
print(len(locat))
appended_data4 =pd.DataFrame()
for location in locat:
all_df = tr_data[tr_data['Location']==location].groupby('Date')['Fatalities'].sum().reset_index()
df_prophet = all_df.loc[:,['Date', 'Fatalities']]
df_prophet.columns = ['ds','y']
m_d = Prophet(interval_width=0.95, yearly_seasonality= True,
weekly_seasonality = True,
daily_seasonality = True,
seasonality_mode = 'additive')
 m_d.fit(df_prophet)
 future_d = m_d.make_future_dataframe(periods=35)
 fcst_daily = m_d.predict(future_d)
 fcst_daily['Loca']=location
data=fcst_daily[['ds','Loca', 'yhat']]
appended_data4=appended_data4.append(data,ignore_index=True)
 appended_data4.rename(columns={'yhat':'Fatalities'}, inplace=True)
 appended_data4.rename(columns={'Loca':'Location'}, inplace=True)
 appended_data4['Location'].str.strip()
appended_data4['Date']=appended_data4['ds'].dt.strftime('%Y-%m-%d')
 sub4=pd.merge(sub3,appended_data4, on=('Date','Location'),how='left')
 sub4.columns
test_d=test[test["Date"] > max(train['Date'])]
com_data=pd.merge(test,train, on=('Date','Location'),how='inner')
 com_data.rename(columns={'Province_State_x':'Province_State'}, inplace=True)
 com_data.rename(columns={'Country_Region_x':'Country_Region'}, inplace=True)
 com_data.rename(columns={'ConfirmedCases':'confirmed'}, inplace=True)
 com_data.rename(columns={'Fatalities':'death'}, inplace=True)
 com_data.drop(['Province_State_y', 'Country_Region_y','Location'], axis=1)
 after=com_data.drop(columns=['Province_State_y', 'Country_Region_y','Location','Location','Date','Id'])
 sub5=pd.merge(sub4,after, on=('ForecastId'),how='left')
 sub6=sub5[sub5['Date']>'2020-04-09']
sub6=sub6[['ForecastId', 'ConfirmedCases', 'Fatalities']]
sub7=sub5[(sub5['Date']>'2020-04-01')&(sub5['Date']<'2020-04-10')]
sub8=sub7[['ForecastId', 'confirmed', 'death']].reset_index(drop=True)
 sub8.rename(columns={'confirmed':'ConfirmedCases'}, inplace=True)
 sub8.rename(columns={'death':'Fatalities'}, inplace=True)
 subm=sub6.append(sub8,ignore_index=True)
 subb=submission['ForecastId']
subm2=pd.merge(subb,subm,on=('ForecastId'),how='left')
 subm2.columns
tt2=pd.DataFrame()
tt2['ConfirmedCases']=subm2['ConfirmedCases']
tt2['Fatalities']=subm2['Fatalities']
tt2[tt2['Fatalities'] < 0] = 0
tt2[tt2['ConfirmedCases'] < 0] = 0
tt2['ForecastId']=subm2['ForecastId']
tt2.reset_index(drop=True, inplace=True)
 tt2.set_index('ForecastId')
 tt2['Fatalities'].fillna('0', inplace=True)
 tt2['ConfirmedCases'].fillna('0', inplace=True)
 tt2.to_csv("submission.csv", index=False, columns=["ForecastId", "ConfirmedCases", "Fatalities"] )<load_from_csv>
df.to_csv('submission.csv', index=False )