Kaggle competition: COVID19 Global Forecasting (Week 4)
train = pd.read_csv('.. /input/train_V2.csv')
 test = pd.read_csv('.. /input/test_V2.csv')
 submit = pd.read_csv('.. /input/sample_submission_V2.csv' )<prepare_x_and_y>
y_train = train['winPlacePerc']
x_train = train.drop(['Id','groupId','matchId','winPlacePerc', 'matchType'], axis=1)
 x_test = test.drop(['Id','groupId','matchId','matchType'], axis=1 )<feature_engineering>
train = pd.read_csv(".. /input/covid19-global-forecasting-week-4/train.csv")
 test = pd.read_csv(".. /input/covid19-global-forecasting-week-4/test.csv")
 submission = pd.read_csv(".. /input/covid19-global-forecasting-week-4/submission.csv")
x_train['matchDuration'] = x_train['matchDuration'].fillna(x_train['matchDuration'].mean())
 x_test['matchDuration'] = x_test['matchDuration'].fillna(x_test['matchDuration'].mean() )<categorify>
train['Province_State'].fillna(" ", inplace = True)
 test['Province_State'].fillna(" ",inplace = True )
x_train = x_train.fillna(x_train.mean())
 x_test = x_test.fillna(x_test.mean())
 y_train = y_train.fillna(y_train.mean() )<choose_model_class>
train['Country_Region']=train['Country_Region']+' '+train['Province_State']
test['Country_Region']=test['Country_Region']+' '+test['Province_State']
train.drop(['Province_State'],axis = 1 , inplace = True)
 test.drop(['Province_State'],axis = 1 , inplace = True )
reg = XGBRegressor(n_estimators=1650, max_depth=9, learning_rate=0.007 )<train_model>
split_data_train = train["Date"].str.split("-" ).to_list()
split_data_test = test["Date"].str.split("-" ).to_list()
train_date = pd.DataFrame(split_data_train, columns=["Year","Month","Date"])
 test_date = pd.DataFrame(split_data_test, columns=["Year","Month","Date"])
 del train_date["Year"]
del test_date["Year"]
train_date['Month']=train_date['Month'].astype(int)
 test_date['Month']=test_date['Month'].astype(int)
 train_date['Date']=train_date['Date'].astype(int)
 test_date['Date']=test_date['Date'].astype(int)
 del train["Date"]
del test["Date"]
train = pd.concat([train,train_date],axis=1)
 test = pd.concat([test,test_date],axis=1)
reg.fit(x_train, y_train, eval_set=[(x_train, y_train)] )<compute_test_metric>
train_Id = train["Id"]
del train["Id"]
test_Id = test["ForecastId"]
del test["ForecastId"]
reg.score(x_train, y_train )<save_to_csv>
train_x_full = train[['Country_Region','Month','Date']].copy()
train_y_full = train[['ConfirmedCases','Fatalities']].copy()
output = pd.DataFrame()
output['Id'] = submit['Id']
y = reg.predict(x_test)
 y[y<0]=0
output['winPlacePerc'] = y
output.to_csv('output.csv', index=False )<import_modules>
le = LabelEncoder()
train_x_full['Country_Region']=le.fit_transform(train_x_full['Country_Region'])
 test['Country_Region']=le.transform(test['Country_Region'] )
from lightgbm import LGBMRegressor
from sklearn.model_selection import KFold, StratifiedKFold
from sklearn.metrics import mean_absolute_error
import gc
from sklearn.model_selection import GridSearchCV<load_from_csv>
x_train ,x_valid, y_train , y_valid = train_test_split(train_x_full , train_y_full , train_size = 0.85 , test_size = 0.15 )
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )<load_from_csv>
from sklearn.metrics import mean_absolute_error
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from xgboost import XGBRegressor
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )<concatenate>
model = LinearRegression()
model.fit(x_train,y_train)
 preds = model.predict(x_valid)
 print(mean_absolute_error(preds,y_valid))
concat = pd.concat([train, test])
 del train
del test
gc.collect()<drop_column>
model = RandomForestRegressor(n_estimators = 1000)
 model.fit(x_train,y_train)
 preds = model.predict(x_valid)
 print(mean_absolute_error(preds,y_valid))
concat = reduce_mem_usage(concat )<categorify>
model = XGBRegressor(n_estimators = 500, max_depth = 35)
 CC = y_train.ConfirmedCases
fatalities = y_train.Fatalities
model.fit(x_train, CC)
 predCC = model.predict(x_valid)
 model.fit(x_train, fatalities)
 predfa = model.predict(x_valid)
 p = pd.DataFrame({'ConfirmedCases': predCC, 'Fatalities' : predfa})
 print(mean_absolute_error(y_valid, p))
<categorify><EOS> 
CC = train_y_full.ConfirmedCases
fatalities = train_y_full.Fatalities
model.fit(train_x_full, CC)
 predCC = model.predict(test)
 model.fit(train_x_full, fatalities)
 predfa = model.predict(test)
 output = pd.DataFrame({'ForecastId': test_Id,'ConfirmedCases': predCC, 'Fatalities' : predfa})
 output = np.around(output , decimals = 0)
 output.to_csv('submission.csv', index=False )