text_plain_output_1.png
from sklearn.ensemble import RandomForestRegressor

from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_absolute_error

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

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')

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)

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)

train_x_full = train[['Country_Region', 'Month', 'Date']].copy()
train_y_full = train[['ConfirmedCases', 'Fatalities']].copy()

model = LinearRegression()
model.fit(x_train, y_train)
preds = model.predict(x_valid)

model = RandomForestRegressor()
model.fit(train_x_full, train_y_full)
preds = model.predict(x_valid)
print(mean_absolute_error(preds, y_valid))