.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/model_selection/example_cross_val_predict.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_model_selection_example_cross_val_predict.py: ============================ Cross-validation predictions ============================ In addition to computing cross-validation scores, you can use cross-validation to produce predictions. Unlike traditional cross-validation, where folds are independent of one another, time-series folds may overlap (particularly in a sliding window). To account for this, folds that forecast the same time step average their forecasts using either a "mean" or "median" (tunable). .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 16-44 .. image-sg:: /auto_examples/model_selection/images/sphx_glr_example_cross_val_predict_001.png :alt: Cross-validated wineind forecasts :srcset: /auto_examples/model_selection/images/sphx_glr_example_cross_val_predict_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none pmdarima version: 2.1.0 [CV] fold=0 .......................................................... [CV] fold=1 .......................................................... [CV] fold=2 .......................................................... [CV] fold=3 .......................................................... [CV] fold=4 .......................................................... [CV] fold=5 .......................................................... | .. code-block:: Python print(__doc__) # Author: Taylor Smith import numpy as np import pmdarima as pm from pmdarima import model_selection from matplotlib import pyplot as plt print("pmdarima version: %s" % pm.__version__) # Load the data and split it into separate pieces y = pm.datasets.load_wineind() est = pm.ARIMA(order=(1, 1, 2), seasonal_order=(0, 1, 1, 12), suppress_warnings=True) cv = model_selection.SlidingWindowForecastCV(window_size=150, step=4, h=4) predictions = model_selection.cross_val_predict( est, y, cv=cv, verbose=2, averaging="median") # plot the predictions over the original series x_axis = np.arange(y.shape[0]) n_test = predictions.shape[0] plt.plot(x_axis, y, alpha=0.75, c='b') plt.plot(x_axis[-n_test:], predictions, alpha=0.75, c='g') # Forecasts plt.title("Cross-validated wineind forecasts") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 34.291 seconds) .. _sphx_glr_download_auto_examples_model_selection_example_cross_val_predict.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_cross_val_predict.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_cross_val_predict.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_cross_val_predict.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_