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.873, Time=4.63 sec
 ARIMA(0,1,0)(0,0,0)[12] intercept   : AIC=3049.597, Time=0.07 sec
 ARIMA(1,1,0)(1,0,0)[12] intercept   : AIC=2954.975, Time=2.38 sec
 ARIMA(0,1,1)(0,0,1)[12] intercept   : AIC=2947.028, Time=2.54 sec
 ARIMA(0,1,0)(0,0,0)[12]             : AIC=3047.612, Time=0.09 sec
 ARIMA(2,1,2)(0,0,1)[12] intercept   : AIC=2940.108, Time=4.48 sec
 ARIMA(2,1,2)(1,0,0)[12] intercept   : AIC=2915.651, Time=2.80 sec
 ARIMA(2,1,2)(0,0,0)[12] intercept   : AIC=2986.348, Time=0.25 sec
 ARIMA(2,1,2)(2,0,0)[12] intercept   : AIC=2915.275, Time=24.33 sec
 ARIMA(2,1,2)(2,0,1)[12] intercept   : AIC=2918.411, Time=27.15 sec
 ARIMA(1,1,2)(2,0,0)[12] intercept   : AIC=2925.080, Time=16.35 sec
 ARIMA(2,1,1)(2,0,0)[12] intercept   : AIC=2911.330, Time=31.71 sec
 ARIMA(2,1,1)(1,0,0)[12] intercept   : AIC=2911.555, Time=3.46 sec
 ARIMA(2,1,1)(2,0,1)[12] intercept   : AIC=2914.196, Time=25.42 sec
 ARIMA(2,1,1)(1,0,1)[12] intercept   : AIC=2912.289, Time=3.49 sec
 ARIMA(1,1,1)(2,0,0)[12] intercept   : AIC=2920.327, Time=10.55 sec
 ARIMA(2,1,0)(2,0,0)[12] intercept   : AIC=2928.273, Time=37.00 sec
 ARIMA(3,1,1)(2,0,0)[12] intercept   : AIC=2912.939, Time=42.79 sec
 ARIMA(1,1,0)(2,0,0)[12] intercept   : AIC=2954.804, Time=12.22 sec
 ARIMA(3,1,0)(2,0,0)[12] intercept   : AIC=2914.414, Time=41.17 sec
 ARIMA(3,1,2)(2,0,0)[12] intercept   : AIC=2915.331, Time=47.13 sec
 ARIMA(2,1,1)(2,0,0)[12]             : AIC=2908.221, Time=22.32 sec
 ARIMA(2,1,1)(1,0,0)[12]             : AIC=2909.011, Time=2.94 sec
 ARIMA(2,1,1)(2,0,1)[12]             : AIC=2910.144, Time=18.80 sec
 ARIMA(2,1,1)(1,0,1)[12]             : AIC=2908.093, Time=2.80 sec
 ARIMA(2,1,1)(0,0,1)[12]             : AIC=2933.343, Time=1.79 sec
 ARIMA(2,1,1)(1,0,2)[12]             : AIC=2910.039, Time=13.37 sec
 ARIMA(2,1,1)(0,0,0)[12]             : AIC=2980.096, Time=0.15 sec
 ARIMA(2,1,1)(0,0,2)[12]             : AIC=2921.090, Time=14.33 sec
 ARIMA(2,1,1)(2,0,2)[12]             : AIC=2912.081, Time=22.00 sec
 ARIMA(1,1,1)(1,0,1)[12]             : AIC=2915.531, Time=2.20 sec
 ARIMA(2,1,0)(1,0,1)[12]             : AIC=2925.551, Time=1.99 sec
 ARIMA(3,1,1)(1,0,1)[12]             : AIC=2911.034, Time=3.08 sec
 ARIMA(2,1,2)(1,0,1)[12]             : AIC=2913.397, Time=3.23 sec
 ARIMA(1,1,0)(1,0,1)[12]             : AIC=2952.580, Time=1.58 sec
 ARIMA(1,1,2)(1,0,1)[12]             : AIC=2922.527, Time=2.88 sec
 ARIMA(3,1,0)(1,0,1)[12]             : AIC=2912.590, Time=2.74 sec
 ARIMA(3,1,2)(1,0,1)[12]             : AIC=2913.867, Time=3.75 sec

Best model:  ARIMA(2,1,1)(1,0,1)[12]
Total fit time: 460.132 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=5,
                      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: ( 7 minutes 40.215 seconds)

Gallery generated by Sphinx-Gallery