Kaggle competition: COVID19 Global Forecasting (Week 4)
lecturedata_types_dict = {
'user_id': 'int32',
'part_1': 'int8',
'part_2': 'int8',
'part_3': 'int8',
'part_4': 'int8',
'part_5': 'int8',
'part_6': 'int8',
'part_7': 'int8',
'type_of_concept': 'int8',
'type_of_intention': 'int8',
'type_of_solving_question': 'int8',
'type_of_starter': 'int8'
}
user_lecture_stats_part = user_lecture_stats_part.astype(lecturedata_types_dict )<data_type_conversions>
train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
 submission = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv')
 test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv' )
for column in user_lecture_stats_part.columns:
if(column !='user_id'):
user_lecture_stats_part[column] =(user_lecture_stats_part[column] > 0 ).astype('int8' )<filter>
def use_country(state, country):
if pd.isna(state):
return country
else:
return state
train['Province_State'] = train.apply(lambda x: use_country(x['Province_State'], x['Country_Region']), axis=1)
 test['Province_State'] = test.apply(lambda x: use_country(x['Province_State'], x['Country_Region']), axis=1)
 train['Province_State'].fillna('', inplace=True)
 test['Province_State'].fillna('', inplace=True)
 train['Date'] = pd.to_datetime(train['Date'])
 test['Date'] = pd.to_datetime(test['Date'] )
train_lectures[train_lectures.user_id==5382]<filter>
df_out = pd.DataFrame({'ForecastId': [], 'ConfirmedCases': [], 'Fatalities': []})
 for country in set(train['Country_Region']):
country_df = train[train['Country_Region'] == country]
for state in set(country_df['Province_State']):
df = country_df[country_df['Province_State'] == state]
df['Date'] = df['Date'].dt.strftime("%m%d")
 df['Date'] = df['Date'].astype(int)
 test_df= test[(test['Country_Region'] == country)&(test['Province_State'] == state)]
X_Test_CS_Id = test_df['ForecastId']
test_df['Date'] = test_df['Date'].dt.strftime("%m%d")
 test_df['Date'] = test_df['Date'].astype(int)
 X_Train_CS = df[['Country_Region', 'Province_State', 'Date']]
X_Train_CS['Country_Region'] = 0
X_Train_CS['Province_State'] = 0
X_Test_CS = test_df[['Country_Region', 'Province_State', 'Date']]
X_Test_CS['Country_Region'] = 0
X_Test_CS['Province_State'] = 0
y1_Train_CS = df['ConfirmedCases']
y2_Train_CS = df['Fatalities']
model1 = XGBRegressor(n_estimators=1000)
 model1.fit(X_Train_CS, y1_Train_CS)
 y1_pred = model1.predict(X_Test_CS)
 model2 = XGBRegressor(n_estimators=1000)
 model2.fit(X_Train_CS, y2_Train_CS)
 y2_pred = model2.predict(X_Test_CS)
 df = pd.DataFrame({'ForecastId': X_Test_CS_Id, 'ConfirmedCases': y1_pred, 'Fatalities': y2_pred})
 df_out = pd.concat([df_out, df], axis=0 )
user_lecture_stats_part[user_lecture_stats_part.user_id==5382]<drop_column>
df_out.ForecastId = df_out.ForecastId.astype('int')
 df_out.tail()
df_out.to_csv('submission.csv', index=False )