Kaggle competition: COVID19 Global Forecasting (Week 1)
icu_cleaned = pd.DataFrame()
icu_cleaned["country"] = icu_df["Country Name"]
icu_cleaned["icu"] = np.nan
for year in range(1960, 2020):
year_df = icu_df[str(year)].dropna()
icu_cleaned["icu"].loc[year_df.index] = year_df.values<merge>
%matplotlib inline
data = pd.merge(data, icu_cleaned, on='country' )<load_from_csv>
filename = ".. /input/covid19-global-forecasting-week-1/train.csv"
dt = pd.read_csv(filename)
df_temperature = pd.read_csv(".. /input/covid19-global-weather-data/temperature_dataframe.csv")
 df_temperature['country'] = df_temperature['country'].replace('USA', 'US')
 df_temperature['country'] = df_temperature['country'].replace('UK', 'United Kingdom')
 df_temperature = df_temperature[["country", "province", "date", "humidity", "sunHour", "tempC", "windspeedKmph"]].reset_index()
df_temperature.rename(columns={'province': 'state'}, inplace=True)
 df_temperature["date"] = pd.to_datetime(df_temperature['date'])
 df_temperature['state'] = df_temperature['state'].fillna('')
 df_temperature.info()<save_to_csv>
series = read_csv('.. /input/covid19-global-forecasting-week-1/train.csv', header=0, index_col=0, parse_dates=True, squeeze=True)
 series.plot()
pyplot.show()
data = data.merge(df_temperature, on=['country','date', 'state'], how='inner')
 data.to_csv("countries_icu_temp.csv" )<feature_engineering>
filename = ".. /input/hubei-china-data/Hubei_China_2.csv"
df = pd.read_csv(filename)
threshold = 0
train_data['infectionRate'] = round(( train_data['confirmed']/train_data['population'])*100, 5)
 train_data = train_data[train_data['infectionRate'] >= threshold]
print(train_data.shape )<drop_column>
series = read_csv('.. /input/hubei-china-data/Hubei_China_2.csv', header=0, index_col=0, parse_dates=True, squeeze=True)
 series.plot()
pyplot.show()
train_data = train_data.drop([
"country",
"active",
"recovered",
"infectionRate",
"state",
"Lat",
"Long",
"date",
"index"
], axis= 1 ).dropna()
y = train_data[["confirmed", "deaths"]]
X = train_data.drop(["confirmed", "deaths"],axis=1)
 display(X.head())
 print(X.shape, y.shape )<import_modules>
filename = ".. /input/daytoday-china-hubei/DayToDay.csv"
df = pd.read_csv(filename )
from sklearn.preprocessing import StandardScaler 
<compute_test_metric>
series = read_csv('.. /input/daytoday-china-hubei/DayToDay.csv', header=0, index_col=0, parse_dates=True, squeeze=True)
 series.plot()
pyplot.show()
def rmsle(y_true, y_pred):

 return np.sqrt(mean_squared_log_error(y_true, y_pred))
rmsle_scorer = make_scorer(rmsle)
 X_train, X_val, y_train, y_val = tts(X, y, test_size= 0.2, random_state=42, shuffle=True )<compute_train_metric>
filename = ".. /input/submissioncsv/submission.csv"
df = pd.read_csv(filename)
model_infected = DecisionTreeRegressor(random_state=42, criterion="mae")
 scores = cross_val_score(model_infected,
X_train,
y_train["confirmed"],
cv=5, scoring=rmsle_scorer)
 print("Cross Validation of Confirmed Cases: Mean = {}, std = {}".format(scores.mean() , scores.std()))
model_infected.fit(X_train, y_train["confirmed"])
 result_infected = rmsle(y_val["confirmed"], model_infected.predict(X_val))
print("Validation Infected set RMSLE: {}".format(result_infected))<compute_train_metric>
series = read_csv('.. /input/submissioncsv/submission.csv', header=0, index_col=0, parse_dates=True, squeeze=True)
 series.plot()
pyplot.show()
model_deaths = DecisionTreeRegressor(random_state=42, criterion="mae")
 scores = cross_val_score(model_deaths,
X_train,
y_train["deaths"],
cv=5, scoring=rmsle_scorer)
 print("Cross Validation of Fatal Cases: Mean = {}, std = {}".format(scores.mean() , scores.std()))
model_deaths.fit(X_train, y_train["deaths"])
 result_deaths = rmsle(y_val["deaths"], model_deaths.predict(X_val))
print("Validation Death set RMSLE: {}".format(result_deaths))<compute_test_metric>
series = read_csv('.. /input/submissioncsv/submission.csv', header=0, index_col=0, parse_dates=True, squeeze=True)
 lag_plot(series )
print("Final Validatio score: {}".format(np.mean([result_infected, result_deaths])) )<train_model>
Submission.to_csv('submission.csv',index=False )