3

I am dealing with intermittent time series data, i.e. mostly zeros. Here is the particular time series that is giving me trouble:

[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 60.0, 0.0, 0.0, 0.0, 0.0, 36.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 96.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 24.0]

This is fit with an “auto arima” model, which basically just picks the “optimal” arima orders through a backtesting procedure. In this case, ARIMA(2, 0, 2) performs best historically (when using a portion of the data as the train set, and another as the test set).

However, when I fit all of this data with an ARIMA(2, 0, 2) model from statsmodels.api.tsa.SARIMAX, I get a flat forecast with an absurdly large value of 8.278163e+14. Here is the code to reproduce the error:

import statsmodels.api as sm
import numpy as np

y = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 60.0, 0.0, 0.0, 0.0, 0.0, 36.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 96.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 24.0])

mod_kwargs = {'order': (2, 0, 2), 'trend': 'c', 'seasonal_order': None}

model = sm.tsa.SARIMAX(endog=y, **mod_kwargs) model = model.fit(disp=False)

forecast = model.get_forecast(steps=12).predicted_mean

with the following versions: statsmodels==0.14.0, numpy==1.26.1.

Does anyone know what could cause something like this? Is it possibly a bug in the statsmodels package itself, or could an ARIMA model genuinely return a result like this in very specific circumstances?

UPDATE: I just repeated this experiment in R and the results look perfectly reasonable. This makes me think there is a bug in the statsmodels package.

  • 1
    ARIMA is absolutely not the correct model or forecasting method for this kind of data. In addition, ARIMA(2,0,2) is much too complicated. If this appears best, then you are overfitting to the holdout data. Much better to use a method based on information criteria, which will penalize spurious complexity. In R, forecast::auto.arima() will give you an ARIMA(0,0,0) model with a nonzero mean - i.e., the simple historical mean as a forecast. If you do force R to fit and forecast an ARIMA(2,0,2) model, it gives you a more useful decay towards the overall mean. – Stephan Kolassa Nov 29 '23 at 07:34
  • This thread contains pointers to literature on forecasting. Per above, ARIMA (or exponential smoothing) are absolutely not what you want to do for intermittent time series. These are quite a challenge in themselves, and most forecasting books will devote an entire chapter to them (plus of course the textbook by Boylan & Syntetos). The go-to method for expectation forecasts is Croston, but such expectation forecasts are especially useless in intermittent series. – Stephan Kolassa Nov 29 '23 at 07:39
  • I am aware that ARIMA is not the ideal model in this situation. I should have been more clear in my post - for privacy reasons I can't get into why, but in this particular case I need to use this model. The question isn't necessarily whether I should, it's just "what could possibly cause the results to blow up like this?" – Justin Furlotte Nov 29 '23 at 13:25
  • 2
    OK, fair enough. I agree that whether or not ARIMA is appropriate here, it should not blow up like this. I have upvoted and hope someone with more Python-fu than I can address your actual question. It does look like a bug. – Stephan Kolassa Nov 29 '23 at 13:28

0 Answers0