Search code examples
pythonpredictionstatsmodelsforecastingarima

ARIMA Forecasting based on real values


I made a ARIMA model for forecasting of electricity cumsumption. The best AR I and AM coefficient I also detected (1,0,6). The values are measure every five minutes and imported as a csv file. One day ist modelling the timeseries and the other day is prediction. My code is the following:

from statsmodels.tsa.arima_model import ARIMA
rcParams['figure.figsize'] = 15, 10
timeseries = df_5min['2010-07-06']
model = ARIMA(timeseries, order=(1,0,6))
result_AR = model.fit(disp=-1)
time_series_df = result_AR.fittedvalues

result_AR.plot_predict(1,600, alpha=0.05)
x = result_AR.forecast(steps=600)
plt.plot(linewidth=1, legend=None)
plt.ylabel('Verbrauch (W)')
plt.xlabel('Zeit (t)')
plt.show()

The output is ARIMA FORECAST

As you can see, the forecast is realy bad. ARIMA works with regression, so it takes the last values and based on them it predicts the next one.

My question is now: I also have the real values for the predicted day(07-08 Jul). Now I want that ARIMA predict only the next six steps e.g., based on the last six real values. After predicting the sex steps, it takes again the last six real values and based on them, it predicts the next six e.g.


Solution

  • If possible, you should switch to using the SARIMAX model, which has more features and will be better supported going forwards (the ARIMA model will be deprecated in the next release). So you should use

    from statsmodels.tsa.api import SARIMAX
    model = SARIMAX(timeseries, order=(1, 0, 6))
    ...
    

    The results object will then have methods called extend and append that will allow you to create a new results object that is extended with your new values. The "Cross-validation" section of this example notebook has some examples of using extend.