.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/arima/example_persisting_a_model.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _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
.. GENERATED FROM PYTHON SOURCE LINES 14-50 .. rst-class:: sphx-glr-script-out .. code-block:: none Predictions: array([21966.69716806, 25983.70920106, 30225.30978922, 35417.12496473, 13011.36188401, 19639.41027934, 21506.58176453, 23674.3399863 , 21685.76394592, 23669.77819202, 26955.35256519, 22755.2506242 , 19808.16133461, 23578.78185402, 27845.86720549, 32923.89427525, 10475.68779115, 17024.74534503, 18831.64798473, 20929.54672618, 18876.02415795, 20792.57513957, 24011.97548591, 19745.03908596, 16731.45365409, 20435.40472322, 24635.90940413, 29647.31032454, 7132.5009883 , 13614.94375569, 15355.23772246, 17386.5246592 , 15266.39189057, 17116.33184996, 20269.12159506, 15935.57437822, 12855.37823992, 16492.71854604, 20626.61249293, 25571.40266446, 2989.98258695, 9405.81460918, 11079.49783278, 13044.17402533, 10857.43051304, 12640.75972849, 15726.93872979, 11326.78076908, 8179.97388695, 11750.70344922, 15817.98665226]) | .. 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 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.200 seconds) .. _sphx_glr_download_auto_examples_arima_example_persisting_a_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_persisting_a_model.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_persisting_a_model.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_persisting_a_model.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_