Kaggle competition: COVID19 Global Forecasting (Week 4)
del cum
gc.collect()<categorify>
X_train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
 X_test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
 X_train.rename(columns={'Country_Region':'Country'}, inplace=True)
 X_test.rename(columns={'Country_Region':'Country'}, inplace=True)
 X_train.rename(columns={'Province_State':'State'}, inplace=True)
 X_test.rename(columns={'Province_State':'State'}, inplace=True)
 X_train.Date = pd.to_datetime(X_train.Date, infer_datetime_format=True)
 X_test.Date = pd.to_datetime(X_test.Date, infer_datetime_format=True)
 EMPTY_VAL = "EMPTY_VAL"
def fillState(state, country):
if state == EMPTY_VAL: return country
return state
X_xTrain = X_train.copy()
X_xTrain.State.fillna(EMPTY_VAL, inplace=True)
 X_xTrain.State = X_xTrain.loc[:, ['State', 'Country']].apply(lambda x : fillState(x['State'], x['Country']), axis=1)
 X_xTrain.loc[:, 'Date'] = X_xTrain.Date.dt.strftime("%m%d")
 X_xTrain.Date = X_xTrain.Date.astype(int)
 X_xTest = X_test.copy()
X_xTest.State.fillna(EMPTY_VAL, inplace=True)
 X_xTest.State = X_xTest.loc[:, ['State', 'Country']].apply(lambda x : fillState(x['State'], x['Country']), axis=1)
 X_xTest.loc[:, 'Date'] = X_xTest.Date.dt.strftime("%m%d")
 X_xTest.Date = X_xTest.Date.astype(int )
content_agg = train_df.groupby('content_id')[target].agg(['sum', 'count','var'])
 task_container_agg = train_df.groupby('task_container_id')[target].agg(['sum', 'count','var'])
 content_agg=content_agg.astype('float32')
 task_container_agg=task_container_agg.astype('float32' )<data_type_conversions>
le = preprocessing.LabelEncoder()
X_xTrain.Country = le.fit_transform(X_xTrain.Country)
 X_xTrain.State = le.fit_transform(X_xTrain.State)
 X_xTest.Country = le.fit_transform(X_xTest.Country)
 X_xTest.State = le.fit_transform(X_xTest.State )
train_df['task_container_uncor_count'] = train_df['task_container_id'].map(task_container_agg['count']-task_container_agg['sum'] ).astype('int32')
 train_df['task_container_cor_count'] = train_df['task_container_id'].map(task_container_agg['sum'] ).astype('int32')
 train_df['task_container_std'] = train_df['task_container_id'].map(task_container_agg['var'] ).astype('float16')
 train_df['task_container_correctness'] = train_df['task_container_id'].map(task_container_agg['sum'] / task_container_agg['count'])
 train_df.task_container_correctness=train_df.task_container_correctness.astype('float16' )<groupby>
filterwarnings('ignore')
 le = preprocessing.LabelEncoder()
countries = X_xTrain.Country.unique()
content_elapsed_time_agg=train_df.groupby('content_id')['prior_question_elapsed_time'].agg(['mean'])
 content_had_explanation_agg=train_df.groupby('content_id')['prior_question_had_explanation'].agg(['mean'] )<train_model>
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 )
print('start questions data...' )<load_from_csv>
xdata = pd.DataFrame({'ForecastId': X_xTest_CS_Id, 'ConfirmedCases': y1_xpred, 'Fatalities': y2_xpred})
 xout = pd.concat([xout, xdata], axis=0 )
<groupby><EOS> 
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 )