Kaggle competition: COVID19 Global Forecasting (Week 4)
print('start handle timestamp...')
 prior_question_elapsed_time_mean=train_df['prior_question_elapsed_time'].mean()
train_df['prior_question_elapsed_time'].fillna(prior_question_elapsed_time_mean, inplace=True )<data_type_conversions>
train = pd.read_csv("/kaggle/input/covid19-global-forecasting-week-4/train.csv")
 train.rename(columns={'Country_Region':'Country'}, inplace=True)
 train.rename(columns={'Province_State':'State'}, inplace=True)
 train['Date'] = pd.to_datetime(train['Date'], infer_datetime_format=True)
 train['Date'] = train.Date.dt.strftime("%m%d")
 train['Date'] = train['Date'].astype(int)
 train["State"].fillna("",inplace=True)
 train["CountryState"] = train["Country"] + train["State"]
print("train done")
 test = pd.read_csv("/kaggle/input/covid19-global-forecasting-week-4/test.csv")
 test.rename(columns={'Country_Region':'Country'}, inplace=True)
 test.rename(columns={'Province_State':'State'}, inplace=True)
 test['Date'] = pd.to_datetime(test['Date'], infer_datetime_format=True)
 test['Date'] = test.Date.dt.strftime("%m%d")
 test['Date'] = test['Date'].astype(int)
 test["State"].fillna("",inplace=True)
 test["CountryState"] = test["Country"] + test["State"]
print("test done")
max_timestamp_u = train_df[['user_id','timestamp']].groupby(['user_id'] ).agg(['max'] ).reset_index()
max_timestamp_u.columns = ['user_id', 'max_time_stamp']
max_timestamp_u.user_id=max_timestamp_u.user_id.astype('int32' )<data_type_conversions>
%%time
filterwarnings('ignore')
 le = LabelEncoder()
finaloutput = pd.DataFrame({'ForecastId': [], 'ConfirmedCases': [], 'Fatalities': []})
 CountryState = train.CountryState.unique()
for CS in CountryState:
trainIndia = train[train["CountryState"] == CS]
testIndia = test[test["CountryState"] == CS]
trainIndia.CountryState = le.fit_transform(trainIndia.CountryState)
 X = trainIndia[['CountryState', 'Date']]
Y = trainIndia[['ConfirmedCases']]
eval_set = [(X,Y)]
model1 = boostmodel(learning_rate=0.3,silent=0, n_estimators=1000)
 model1.fit(X, Y,eval_set=eval_set,early_stopping_rounds=100)
 testX = testIndia[['CountryState', 'Date']]
testX.CountryState = le.fit_transform(testX.CountryState)
 ConfirmedCases_Pred = model1.predict(testX)
 X = trainIndia[['CountryState', 'Date']]
Y = trainIndia[['Fatalities']]
eval_set = [(X,Y)]
model2 = boostmodel(learning_rate=0.3,silent=0, n_estimators=1000)
 model2.fit(X, Y,eval_set=eval_set,early_stopping_rounds=100)
 testX = testIndia[['CountryState', 'Date']]
testX.CountryState = le.fit_transform(testX.CountryState)
 Fatalities_Pred = model2.predict(testX)
 XForecastId = testIndia.loc[:, 'ForecastId']
output = pd.DataFrame({'ForecastId': XForecastId, 'ConfirmedCases': ConfirmedCases_Pred, 'Fatalities': Fatalities_Pred})
 finaloutput = pd.concat([finaloutput, output], axis=0)
 print("Program completed" )
train_df['lagtime'] = train_df.groupby('user_id')['timestamp'].shift()
max_timestamp_u2 = train_df[['user_id','lagtime']].groupby(['user_id'] ).agg(['max'] ).reset_index()
max_timestamp_u2.columns = ['user_id', 'max_time_stamp2']
max_timestamp_u2.user_id=max_timestamp_u2.user_id.astype('int32' )<feature_engineering>
finaloutput.ConfirmedCases.apply(math.floor )
<data_type_conversions><EOS> 
finaloutput.ForecastId = finaloutput.ForecastId.astype('int')
 finaloutput.ConfirmedCases = round(finaloutput.ConfirmedCases,1)
 finaloutput.Fatalities = round(finaloutput.Fatalities,1)
 finaloutput = finaloutput[['ForecastId','ConfirmedCases','Fatalities']]
finaloutput.to_csv("submission.csv",index=False)
 print("done" )