.. _sphx_glr_auto_examples_arima_example_persisting_a_model.py:
=========================
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.
.. raw:: html
.. rst-class:: sphx-glr-script-out
Out::
Predictions: array([21966.69715674, 25983.70919719, 30225.30978371, 35417.12495804,
13011.36187769, 19639.41027228, 21506.58175753, 23674.33997867,
21685.76393805, 23669.778184 , 26955.35255653, 22755.25061482,
19808.16131817, 23578.78184187, 27845.86719195, 32923.89426059,
10475.68777621, 17024.74532948, 18831.64796876, 20929.54670952,
18876.02414073, 20792.57512203, 24011.97546746, 19745.0390666 ,
16731.45362742, 20435.40470062, 24635.90937992, 29647.31029897,
7132.50096224, 13614.94372878, 15355.23769491, 17386.52463074,
15266.39186131, 17116.33182016, 20269.12156413, 15935.57434614,
12855.37820032, 16492.71851028, 20626.61245533, 25571.40262528,
2989.98254705, 9405.81456821, 11079.49779094, 13044.17398235,
10857.43046903, 12640.75968372, 15726.93868366, 11326.78072158,
8179.9738317 , 11750.70339758, 15817.98659857])
|
.. code-block:: python
print(__doc__)
# Author: Taylor Smith
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 3.320 seconds)
.. only :: html
.. container:: sphx-glr-footer
.. container:: sphx-glr-download
:download:`Download Python source code: example_persisting_a_model.py `
.. container:: sphx-glr-download
:download:`Download Jupyter notebook: example_persisting_a_model.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_