Simple auto_arima modelΒΆ

This is a simple example of how we can fit an ARIMA model in several lines without knowing anything about our data or optimal hyper parameters.


../_images/sphx_glr_example_simple_fit_001.png

Out:

Performing stepwise search to minimize aic
 ARIMA(2,1,2)(1,0,1)[12] intercept   : AIC=2915.641, Time=0.37 sec
 ARIMA(0,1,0)(0,0,0)[12] intercept   : AIC=3049.597, Time=0.01 sec
 ARIMA(1,1,0)(1,0,0)[12] intercept   : AIC=2954.973, Time=0.23 sec
 ARIMA(0,1,1)(0,0,1)[12] intercept   : AIC=2947.014, Time=0.25 sec
 ARIMA(0,1,0)(0,0,0)[12]             : AIC=3047.612, Time=0.01 sec
 ARIMA(2,1,2)(0,0,1)[12] intercept   : AIC=2938.457, Time=0.40 sec
 ARIMA(2,1,2)(1,0,0)[12] intercept   : AIC=2915.636, Time=0.36 sec
 ARIMA(2,1,2)(0,0,0)[12] intercept   : AIC=2984.606, Time=0.10 sec
 ARIMA(2,1,2)(2,0,0)[12] intercept   : AIC=2915.168, Time=3.81 sec
 ARIMA(2,1,2)(2,0,1)[12] intercept   : AIC=2917.256, Time=3.69 sec
 ARIMA(1,1,2)(2,0,0)[12] intercept   : AIC=2924.379, Time=3.23 sec
 ARIMA(2,1,1)(2,0,0)[12] intercept   : AIC=2911.007, Time=3.77 sec
 ARIMA(2,1,1)(1,0,0)[12] intercept   : AIC=2911.505, Time=0.35 sec
 ARIMA(2,1,1)(2,0,1)[12] intercept   : AIC=2912.933, Time=3.54 sec
 ARIMA(2,1,1)(1,0,1)[12] intercept   : AIC=2911.904, Time=0.26 sec
 ARIMA(1,1,1)(2,0,0)[12] intercept   : AIC=2919.168, Time=1.68 sec
 ARIMA(2,1,0)(2,0,0)[12] intercept   : AIC=2927.636, Time=3.07 sec
 ARIMA(3,1,1)(2,0,0)[12] intercept   : AIC=2912.748, Time=5.72 sec
 ARIMA(1,1,0)(2,0,0)[12] intercept   : AIC=2954.725, Time=2.51 sec
 ARIMA(3,1,0)(2,0,0)[12] intercept   : AIC=2914.169, Time=3.70 sec
 ARIMA(3,1,2)(2,0,0)[12] intercept   : AIC=2915.130, Time=3.36 sec
 ARIMA(2,1,1)(2,0,0)[12]             : AIC=2908.085, Time=2.34 sec
 ARIMA(2,1,1)(1,0,0)[12]             : AIC=2908.791, Time=0.31 sec
 ARIMA(2,1,1)(2,0,1)[12]             : AIC=2909.997, Time=2.76 sec
 ARIMA(2,1,1)(1,0,1)[12]             : AIC=2907.980, Time=0.32 sec
 ARIMA(2,1,1)(0,0,1)[12]             : AIC=2932.875, Time=0.32 sec
 ARIMA(2,1,1)(1,0,2)[12]             : AIC=2909.946, Time=7.37 sec
 ARIMA(2,1,1)(0,0,0)[12]             : AIC=2979.838, Time=0.11 sec
 ARIMA(2,1,1)(0,0,2)[12]             : AIC=2920.616, Time=3.41 sec
 ARIMA(2,1,1)(2,0,2)[12]             : AIC=2911.929, Time=7.60 sec
 ARIMA(1,1,1)(1,0,1)[12]             : AIC=2915.102, Time=0.41 sec
 ARIMA(2,1,0)(1,0,1)[12]             : AIC=2925.280, Time=0.35 sec
 ARIMA(3,1,1)(1,0,1)[12]             : AIC=2910.007, Time=1.14 sec
 ARIMA(2,1,2)(1,0,1)[12]             : AIC=2913.030, Time=0.62 sec
 ARIMA(1,1,0)(1,0,1)[12]             : AIC=2952.472, Time=0.31 sec
 ARIMA(1,1,2)(1,0,1)[12]             : AIC=2922.341, Time=0.47 sec
 ARIMA(3,1,0)(1,0,1)[12]             : AIC=2912.111, Time=0.37 sec
 ARIMA(3,1,2)(1,0,1)[12]             : AIC=2913.230, Time=0.49 sec

Best model:  ARIMA(2,1,1)(1,0,1)[12]
Total fit time: 69.155 seconds

print(__doc__)

# Author: Taylor Smith <taylor.smith@alkaline-ml.com>

import pmdarima as pm
from pmdarima import model_selection
import numpy as np
from matplotlib import pyplot as plt

# #############################################################################
# Load the data and split it into separate pieces
data = pm.datasets.load_wineind()
train, test = model_selection.train_test_split(data, train_size=150)

# Fit a simple auto_arima model
arima = pm.auto_arima(train, error_action='ignore', trace=True,
                      suppress_warnings=True, maxiter=10,
                      seasonal=True, m=12)

# #############################################################################
# Plot actual test vs. forecasts:
x = np.arange(test.shape[0])
plt.scatter(x, test, marker='x')
plt.plot(x, arima.predict(n_periods=test.shape[0]))
plt.title('Actual test samples vs. forecasts')
plt.show()

Total running time of the script: ( 1 minutes 9.181 seconds)

Gallery generated by Sphinx-Gallery