SARIMAX: Restoring initial values after differencing

77 views
Skip to first unread message

Вячеслав Загородин

unread,
Nov 3, 2021, 10:34:40 AM11/3/21
to pystatsmodels
Hello,

I've been experimenting with simple_differencing=True but i don't understand how to restore the initial values after predition.

I have a function that reverses differencing of order 'n' given 'n' first values of the initial array and it works fine, i've tested it many times. For example, i can restore values of a time series after taking both seasonal and first differencies.

But when i apply this to sarima predictions it doesn't work: the result differs drastically from the same prediction with simple_differencing=False and from the initial time series.

Can you, please, explain how to retore the initial values correctly?

Вячеслав Загородин

unread,
Nov 8, 2021, 5:52:12 AM11/8/21
to pystatsmodels
Hi,
I'm not sure if my question makes any sense, but i'd like to provide a simple illustration of what i'm talking about.

Here i have two identical forecasts with the only difference being simple_difference parameter.
Then i test my inverse_diff function that perfectly restores the initial time series after differencing.
But, as i said before, when i apply it to forecast_simple it doesn't work at all.
This happens regardless of the time series or SARIMA orders i choose.

I would really appreciate if you gave me some insights on what i'm doing wrong.

restoring_test_code.pngrestoring_test.png

среда, 3 ноября 2021 г. в 17:34:40 UTC+3, Вячеслав Загородин:

Вячеслав Загородин

unread,
Nov 8, 2021, 6:07:11 AM11/8/21
to pystatsmodels
There are two more facts i'd like to mention

1. Another really strange thing that i noticed is that when i divide forecast_simple by the sum of SARIMA coefficients as shown below, the result gets much better. It doesn't work really well when using both first and seasonal differencies, but still somehow makes the forecast better.
With (p, 1, 0)x(0,0,0,0) models it works way better and almost restores the actual forecast.
I have no idea what happens when i do this, i discovered it by accident, but the result looks like the initial time series shifted towards future values.
It would be great if you could also explain this.

inversed_forecast = my_ts.inverse_diff(forecast_simple / sarima_simple.params[:-1].sum(),\
                                       time_series[:31],\
                                       orders=[30, 1])

2. I tried to recreate the same procedure using just LinearRegression from sklearn. I forecasted the differenced time series using 'p' usual lags and 'P' seasonal lags. It gives almost the same coefficients and results as SARIMA and i also can't restore the time series after that.
понедельник, 8 ноября 2021 г. в 13:52:12 UTC+3, Вячеслав Загородин:
Reply all
Reply to author
Forward
0 new messages