Why doesn't ARIMA work on my time series data?

I use auto_arima from python library pmdarima.arima to predict a time series. However, the model seems not work on my data because the prediction results of both training and test data are pretty bad. I would like to know it is because somewhere I did wrong or the data is unpredictable by ARIMA. Here is what I did.

b is my 5-month time series with 700 observations evenly distributed. I first checked if the data is stationary by ADCF.

from statsmodels.tsa.stattools import adfuller

print("Results of Dicky-Fuller Test:")
dftest = adfuller(b, autolag='AIC')

dfoutput = pd.Series(dftest[0:4], index=['ADF Statistic','p-value','#Lags Used','Number of Observations Used'])
for key,value in dftest[4].items():
dfoutput['Critical Value (%s)'%key] = value

print(dfoutput)


The results are here

-----------------------------------------
Results of Dicky-Fuller Test:
ADF Statistic                   -2.045778
p-value                          0.266868
#Lags Used                       9.000000
Number of Observations Used    690.000000
Critical Value (1%)             -3.439863
Critical Value (5%)             -2.865738
Critical Value (10%)            -2.569005
dtype: float64
-----------------------------------------


It looks a stationary data to me. Then I use auto_arima to find the best parameter combinations and do the fit as well as prediction

from pmdarima.arima import auto_arima

model = auto_arima(b, start_p=1, start_q=1,
max_p=6, max_q=6, m=1,
seasonal=False,
d=0, trace=True,
error_action='warn',
suppress_warnings=True,
stepwise=True)
print(model.aic())

model.fit(train)

prediction1 = model.predict(n_periods=len(train))
prediction2 = model.predict(n_periods=len(test))

#plot the predictions for validation set
plt.plot(time_train,train, label='train')
plt.plot(time_test,test, label='test')
plt.plot(time_train, prediction1, label='prediction1')
plt.plot(time_test, prediction2, label='prediction2')
plt.legend()
plt.show()


And the results are

Could anyone please tell me what I did wrong? Thanks! Edit: I understand that the train_prediction curve shown above is actually not the prediction of training data -- it is the predictions of time series len(train) time stamps after the traning data.

• Why have you set seasonality to be false? Your data is clearly periodic. – tchakravarty Jun 5 '19 at 14:59
• Your plot is incorrect (and clearly was not produced by the code you show): the green curve ("train_prediction") has been shifted four months to the left of where it ought to be. Please tell us in what sense the predictions are "pretty bad" and how you have confirmed that. – whuber Jun 5 '19 at 15:54
• What makes you think it doesn't work? – Aksakal Jun 5 '19 at 16:03
• @tchakravarty I tried seaonsonal=True also. But the final plot does not change much. The data is roughly bi-weekly periodic. – Zhendong Jun 5 '19 at 19:22
• @whuber thank you for the comments. The plot was created by the code. I drew the conclusion of "pretty bad" just by looking at the picture shown above. The predictions don't match the observational data. Why did you say "he green curve ("train_prediction") has been shifted four months to the left of where it ought to be"? Is the prediction not the real prediction of data based on my code? – Zhendong Jun 5 '19 at 20:15

2 Answers

You have only 5 months worth of data, I assume observed on daily basis. Your cycle is monthly so m should be 30. Also, your data looks seasonal and therefore should set to true.

Don't try to overfit your data and simply use the default on your first run:

auto_arima(b, error_action='ignore', trace=1,  seasonal=True, m=30)

• Thank you @rainman, I tried the code you provided, and the result showed slight fluctuations but still far away from a "satisfying" prediction. – Zhendong Jun 5 '19 at 20:17
• I checked again the auto_arima document, and I think i m should be 12 to represent monthly cycle, not 30. In the document, "The period for seasonal differencing, m refers to the number of periods in each season. For example, m is 4 for quarterly data, 12 for monthly data, or 1 for annual (non-seasonal) data. " – Zhendong Jun 6 '19 at 14:54
• where do you see seasonality in the data? There are fluctuations, but they don't seem regular. – Skander H. Jun 6 '19 at 16:45
• @SkanderH. Do you know how to check the seasonality of the data? Based on the ADF result, the data is stationary. – Zhendong Jun 6 '19 at 17:08
• @Zhendong if it is stationary then it isn't seasonal, since one of the conditions for making a series stationary is to remove any seasonality. To test the seasonality of a series there is an easy way in R, which is simply to run auto.arima() or ETS() from the forecast package and see if the model returned is a seasonal one, or you can do it the proper way and follow the approach described here – Skander H. Jun 6 '19 at 17:26

You did nothing wrong ! ...you probably just didn't read the fine print or understand the assumptions underlying the statistical test you were employing.

See Interrupted Time Series Analysis - ARIMAX for High Frequency Biological Data? for @AdamO's wise reflection that "The correlogram should be calculated from residuals using a model that controls for intervention administration, otherwise the intervention effects are taken to be Gaussian noise, underestimating the actual autoregressive effect."

In other words for auto.arima to be useful you needed to have the following circumstances.

1) a series with no pulses,level shifts,seasonal pulses or deterministic time structure like trends or day-of-the-week effects or day-of-the-month effects or holiday effects et al .

2) a series where the parameters for the underlying arima model are constant over time

3) a series where the error variance of the underlying arima model does not change deterministically at different time points.

Your time series like most have 1 or more of these possible violations, clearly a level/step shift seems to be present BUT only your data knows for sure . If you post your data I will try and help further.

More interesting reading (13) is here https://stats.stackexchange.com/search?q=user%3A3382+AdamO

• Have you checked this carefully? If the plot is incorrect, something must have been done wrong... – Richard Hardy Jun 5 '19 at 16:35
• that is always a possibility . I didn't make the plot myself. The blue line (if correctly plotted) was sufficient to suggest a level shift (intercept shift ) which underscores @AdamO's remarks. – IrishStat Jun 5 '19 at 19:04
• @IrishStat. Thank you Dave. I sent the data to your email autobox email. – Zhendong Jun 5 '19 at 20:07