marcopeix / TimeSeriesForecastingInPython

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Training on test sample in CH05 ??

OdysseusU opened this issue · comments

In CH05, your method rolling_forecasting trains on test samples.

In this case :
the df corresponds to all the data (train AND test).
You are fitting SARIMAX to the train AND test samples.

            model = SARIMAX(df[:i], order=(2,0,0))
            res = model.fit(disp=False)
            predictions = res.get_prediction(0, i + window - 1)
            oos_pred = predictions.predicted_mean.iloc[-window:]
            pred_AR.extend(oos_pred)

In order to really do forecasting, your training should be based on train AND prediction sample.

            model = SARIMAX(df_train_estimated[:i], order=(2,0,0))
            res = model.fit(disp=False)
            predictions = res.get_prediction(0, i + window - 1)
            oos_pred = predictions.predicted_mean.iloc[-window:]
            pred_AR.extend(oos_pred)
            df_train_estimated.append({'value': oos_pred.values[0]}) #Adding the last prediction and use it as training