Running the example loads the dataset as a Pandas Series and prints the first 5 rows.

1

2

3

4

5

6

7

Month

1901-01-01 266.0

1901-02-01 145.9

1901-03-01 183.1

1901-04-01 119.3

1901-05-01 180.3

Name: Sales, dtype: float64

A line plot of the series is then created showing a clear increasing trend.

Line Plot of Monthly Shampoo Sales Dataset

Experimental Test-Setup

It is important to evaluate time series forecasting models consistently.

In this section, we will define how we will evaluate the three forecast models in this tutorial.

First, we will hold the last one year of data back and evaluate forecasts on this data. Given the data is monthly, this means that the last 12 observations will be used as test data.

We will use a walk-forward validation method to evaluate model performance. This means that each time step in the test dataset will be enumerated, a model constructed on history data, and the forecast compared to the expected value. The observation will then be added to the training dataset and the process repeated.

Walk-forward validation is a realistic way to evaluate time series forecast models as one would expect models to be updated as new observations are made available.

Finally, forecasts will be evaluated using root mean squared error, or RMSE. The benefit of RMSE is that it penalizes large errors and the scores are in the same units as the forecast values (car sales per month).

An ARIMA(4,1,0) forecast model will be used as the baseline to explore the additional parameters of the model. This may not be the optimal model for the problem, but is generally skillful against some other hand tested configurations.

Running the example shows a slightly worse RMSE score on this problem, with this ARIMA configuration.

We can see that the constant term (11.xxx) removed from the array of coefficients each iteration.

1

2

3

4

5

...

[-0.90717131 -0.22332019 -0.11240858 -0.04008561]

[-0.88836083 -0.21098412 -0.09046333 -0.02121404]

[-0.89260136 -0.24120301 -0.10243393 -0.03165432]

Test RMSE: 95.061

Experiment on your own problem and determine whether this constant improves performance.

My own experimentation suggests that ARIMA models may be less likely to converge with the trend term disabled, especially when using more than zero MA terms.

The “solver” Parameter

The solver parameter specifies the numerical optimization method to fit the coefficients to the data.

There is often little reason to tune this parameter other than execution speed if you have a lot of data. The differences will likely be quite minor.

The parameter is described as follows:

Solver to be used. The default is ‘lbfgs’ (limited memory Broyden-Fletcher-Goldfarb-Shanno). Other choices are ‘bfgs’, ‘newton’ (Newton-Raphson), ‘nm’ (Nelder-Mead), ‘cg’ – (conjugate gradient), ‘ncg’ (non-conjugate gradient), and ‘powell’. By default, the limited memory BFGS uses m=12 to approximate the Hessian, projected gradient tolerance of 1e-8 and factr = 1e2. You can change these by using kwargs.

Running the example prints the RMSE and time in seconds of each solver.

1

2

3

4

5

6

7

Solver=lbfgs, Test RMSE: 81.545, Time=1.630316

Solver=bfgs, Test RMSE: 81.545, Time=2.122630

Solver=newton, Test RMSE: 81.545, Time=2.418718

Solver=nm, Test RMSE: 81.472, Time=1.432801

Solver=cg, Test RMSE: 81.543, Time=3.474055

Solver=ncg, Test RMSE: 81.545, Time=2.643767

Solver=powell, Test RMSE: 81.704, Time=1.839257

A graph of solver vs RMSE is provided. As expected, there is little difference between the solvers on this small dataset.

You may see different results or different stability of the solvers on your own problem.

ARIMA Model Error (Test RMSE) vs Solver

A graph of solver vs execution time in seconds is also created. The graph shows a marked difference between solvers.

Generally, “lbfgs” and “bfgs” provide good real-world tradeoff between speed, performance, and stability.

ARIMA Execution Time (seconds) vs Solver

If you do decide to test out solvers, you may also want to vary the “maxiter” that limits the number of iterations before converge, the “tol” parameter that defines the precision of convergence, and the “method” parameter that defines the cost function being optimized.

Additional Resources

This section lists some resources you may find useful alongside this tutorial.

Then I seem to be on the right way.
I have training and predictions strictly separated in my batch environment (menu).
For predictions I always use the complete data, except of one row/x to predict unseen data.
Is this right in general?

Hi Sir
I am applying ARIMA model on my CDR dataset. I have checked that my data is non stationary (Augmented Dickey-Fuller test)
ADF Statistic: -1.569036
p-value: 0.499127
Critical Values:
1%: -3.478
10%: -2.578
5%: -2.882
Than I have plotted ACF, it showed that my first 15 lag values have autocorrelation value greater then 0.5. so I set ‘p’ parameter 15 (is p =15 is correct ?), and ‘d’ is 1 for stationarity. Could you please guide me how I will find the value of moving average MA(q) q parameter ?
Can I determine the value of ‘q’ parameter by visualizing ACF plot ?
Thanks

Thank you for your post.
Maybe I don’t understand that part, but what can you do to fix the “mle_retvals”, ConvergenceWarning? transparams does not seem to affect that.
Also, have you noticed that .predict predicts one day more than needed?

With regards to applying an ARIMA model to a training time series data, do we first need to ensure that the data exhibits normality and/or stationarity before apply the ARIMA model?
Are both normality and stationarity a prerequisite before we can apply ARIMA to fit and forecast?

Hello,
great tutorial. I found one problem which may or may not be related to my limited understanding of nn’s:

I’ve followed the ‘solver’ section of the tutorial and tried to replicate the solver comparisons. Once I reached the #evaluating forecasts part of the code, and tried to execute the rmse = sqrt…line, I received a ValueError: found input variables with inconsistent number of samples:[13, 1]. I’m pretty sure I have to reshape something somewhere – just not sure where. Help is much appreciated.
Cheers,
P

Hello Jason,
happy new year. I’m using python 3.6.7, with statsmodels version 0.9.0, with pretty much everything else up to date. No worries if it’ll take too much time or trouble to debug btw :).
Cheers,
Paul