Persisting an ARIMA modelΒΆ
This example demonstrates how we can persist an ARIMA model to disk after fitting it. It can then be loaded back up and used to generate forecasts.
Out:
Predictions: array([21966.69715733, 25983.70919801, 30225.30978394, 35417.12495868,
13011.36187901, 19639.41027197, 21506.58175768, 23674.3399782 ,
21685.76393784, 23669.77818253, 26955.352556 , 22755.25061502,
19808.16131847, 23578.78184151, 27845.86719122, 32923.89426012,
10475.68777637, 17024.74532795, 18831.64796761, 20929.54670768,
18876.02413908, 20792.57511906, 24011.97546537, 19745.03906516,
16731.45362601, 20435.40469849, 24635.90937735, 29647.3102966 ,
7132.50096043, 13614.94372521, 15355.23769165, 17386.52462673,
15266.39185742, 17116.33181488, 20269.12155966, 15935.57434226,
12855.3781964 , 16492.71850557, 20626.61245011, 25571.40262018,
2989.98254245, 9405.81456178, 11079.49778475, 13044.17397535,
10857.43046209, 12640.75967531, 15726.938676 , 11326.78071444,
8179.97382445, 11750.70338948, 15817.98658988])
print(__doc__)
# Author: Taylor Smith <taylor.smith@alkaline-ml.com>
import pmdarima as pm
from pmdarima import model_selection
import joblib # for persistence
import os
# #############################################################################
# Load the data and split it into separate pieces
y = pm.datasets.load_wineind()
train, test = model_selection.train_test_split(y, train_size=125)
# Fit an ARIMA
arima = pm.ARIMA(order=(1, 1, 2), seasonal_order=(0, 1, 1, 12))
arima.fit(y)
# #############################################################################
# Persist a model and create predictions after re-loading it
pickle_tgt = "arima.pkl"
try:
# Pickle it
joblib.dump(arima, pickle_tgt, compress=3)
# Load the model up, create predictions
arima_loaded = joblib.load(pickle_tgt)
preds = arima_loaded.predict(n_periods=test.shape[0])
print("Predictions: %r" % preds)
finally:
# Remove the pickle file at the end of this example
try:
os.unlink(pickle_tgt)
except OSError:
pass
Total running time of the script: ( 0 minutes 2.652 seconds)