Solved – ARIMA model with least AIC giving negative forecasts even though there are no negative values in the training data

arimaforecastingtime series

I'm training a arima model on a daily time series data where I'm trying to forecast daily inflow counts of a request on a particular day. It can be either positive or zero (no zero requests in the data I'm dealing with) but can never be negative. I'm using ARIMA model from statsmodels library. The process I'm doing involves following steps

  1. The arima model parameters p ranges from (0,10), d ranges from (0,3), q ranges from (0,5)
  2. The model will try all possible combinations for (p,d,q) and selects the combination with the least AIC score. In my case, the best combination is (6,2,1) with AIC of 7204.084892

When I plotted my forecasts, it is predicting negative inflow requests instead of positive requests. I don't understand this because, in the months leading to the test data set, all the inflows are in thousands but the predictions are negative. Can someone please explain why this is happening? Are there any methods that can be done to the data before passing it to the model?
ARIMA Plot
Train: Data during training period;
Test: Original data during testing period;
Test_predicted: Predictions made for testing period by arima model;

Best Answer

Your forecast is quite obviously badly wrong, and we can tell even without looking at the holdout data.

An ARIMA(6,2,1) model is very complex. The I(2) term can be thought of as modeling quadratic trends in time. (Why? An ARIMA(p,1,q) series has ARMA(p,q) increments, and an ARIMA(p,2,q) series has ARMA(p,q) increments of increments, so overall, something "quadratic" happens. Think in terms of second derivatives!) Here is a little illustration of what kinds of time series happen with I(2) - note the vertical axes:

I(2)

R code:

set.seed(1) # for reproducibility
opar <- par(mfrow=c(4,5),mai=c(.5,.5,.1,.1))
    for ( ii in 1:20 ) plot(arima.sim(model=list(order=c(0,2,0)),n=100),
      xlab="",ylab="",las=1)
par(opar)

First, we don't see these kinds of trends in your data, and second, this can extrapolate very badly indeed. I would be very careful about integration orders higher than 1. Use a simpler model.

I suspect you are calculating AIC values on all your models, and comparing them. You can't compare AICs between models of different integration orders (because the differencing implies that the data are on different scales). You can only compare AICs between models with the same $d$.

I recommend you either use auto.arima() from the forecast package for R, or at least take a look at how it decides on the order of integration. I suspect that auto.arima() will decide on a very different model than one with $d=2$. In Python, you could try pmdarima, which aims at replicating auto.arima(). I don't have any experience with it, though.

Related Question