image_output_1.png
from sklearn.linear_model import Lasso

from sklearn.preprocessing import PolynomialFeatures

import matplotlib.pyplot as plt

import numpy as np # linear algebra

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

train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
submission = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv')

X_train = train[['Id']]
test['Id'] = test['ForecastId']
X_test = test[['Id']]
y_train_cc = train[['ConfirmedCases']]
y_train_ft = train[['Fatalities']]

X_tr = np.array_split(X_train, 313)
y_cc = np.array_split(y_train_cc, 313)
y_ft = np.array_split(y_train_ft, 313)
X_te = np.array_split(X_test, 313)

a = np.max(X_tr[0]).values
b = a - 71
b = b[0]

from sklearn.linear_model import Lasso
from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(3)
y_pred_cc = []
for i in range(313):
    X_tr[i] = poly.fit_transform(X_tr[i])
    X_te[i] = poly.fit_transform(X_te[i])
    model = Lasso(alpha=0.1)
    model.fit(X_tr[i], y_cc[i])
    y_pr_cc = model.predict(X_te[i])
    y_cc[i] = y_cc[i][71:]
    y_pr_cc = y_pr_cc[b:]
    y_pr_cc = np.append(y_cc[i], y_pr_cc)
    y_pred_cc.append(y_pr_cc)

y_pred_ft = []
for i in range(313):
    model = Lasso()
    model.fit(X_tr[i], y_ft[i])
    y_pr_ft = model.predict(X_te[i])
    y_ft[i] = y_ft[i][71:]
    y_pr_ft = y_pr_ft[b:]
    y_pr_ft = np.append(y_ft[i], y_pr_ft)
    y_pred_ft.append(y_pr_ft)