.. _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.69716963, 25983.70921139, 30225.30979747, 35417.12497254, 13011.36188759, 19639.41029019, 21506.58177282, 23674.33999704, 21685.76395507, 23669.77820646, 26955.35257496, 22755.2506303 , 19808.16134242, 23578.78187024, 27845.86722015, 32923.89428919, 10475.68780117, 17024.74536224, 18831.64799954, 20929.54674345, 18876.02417373, 20792.5751607 , 24011.97550244, 19745.03909889, 16731.45366879, 20435.40474641, 24635.90942583, 29647.31034558, 7132.5010055 , 13614.94378014, 15355.23774458, 17386.52468386, 15266.39191381, 17116.33187861, 20269.12161919, 15935.57439881, 12855.37826236, 16492.71857703, 20626.6125225 , 25571.40269344, 2989.98261217, 9405.81464171, 11079.49786305, 13044.17405821, 10857.43054456, 12640.7597655 , 15726.93876234, 11326.78079817, 8179.97391796, 11750.70348884, 15817.98669054]) | .. code-block:: python print(__doc__) # Author: Taylor Smith import pyramid as pm from pyramid.datasets import load_wineind from sklearn.externals import joblib # for persistence import os # ############################################################################# # Load the data and split it into separate pieces y = load_wineind() train, test = y[:125], y[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 1.126 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 `_