.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/forecast/plot_holt_winters_predictor.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_forecast_plot_holt_winters_predictor.py: ================================ Holt-Winters Predictor ================================ For the Holt-Winters example we use forged daily data with a weekly seasonality. We predict two types of data, the first dataset displays an additive trend and an additive seasonality, and the second dataset displays an additive trend and a multiplicative seasonality. .. GENERATED FROM PYTHON SOURCE LINES 12-50 .. image-sg:: /auto_examples/forecast/images/sphx_glr_plot_holt_winters_predictor_001.png :alt: Forecast for data with weekly seasonality and additive trend, Forecast for data with weekly seasonality, additive trend, and multiplicative seasonality :srcset: /auto_examples/forecast/images/sphx_glr_plot_holt_winters_predictor_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/indsl/indsl/.venv/lib/python3.14/site-packages/statsmodels/tsa/base/tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency D will be used. self._init_dates(dates, freq) /home/runner/work/indsl/indsl/.venv/lib/python3.14/site-packages/statsmodels/tsa/base/tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency D will be used. self._init_dates(dates, freq) | .. code-block:: Python from pathlib import Path import warnings import matplotlib.pyplot as plt import pandas as pd from indsl.forecast.holt_winters_predictor import holt_winters_predictor as hwp # suppress "No frequency information was given" warning - Frequency information is derived from datetime index warnings.filterwarnings("ignore") base_path = Path(__file__).parents[2] if "__file__" in globals() else next(p for p in (Path.cwd(), *Path.cwd().parents) if (p / "datasets").exists()) data = pd.read_csv(base_path / "datasets" / "data" / "seasonal_with_trend_data.csv", sep=";", index_col=0) data.index = pd.to_datetime(data.index) # calculate the forecast for both data types additive_res = hwp(data["additive"], seasonal_periods=7, steps=90) multiplicative_res = hwp(data["multiplicative"], seasonal_periods=7, seasonality="mul", steps=90) # plot result fig, ax = plt.subplots(2, 1, figsize=[9, 7]) ax[0].plot(data.index, data["additive"], label="Train") ax[0].plot(additive_res.index, additive_res, label="Holt-Winters") ax[0].set_ylabel("Value") ax[0].set_title("Forecast for data with weekly seasonality and additive trend") ax[1].plot(data.index, data["multiplicative"], label="Train") ax[1].plot(multiplicative_res.index, multiplicative_res, label="Holt-Winters") ax[1].set_title("Forecast for data with weekly seasonality, additive trend, and multiplicative seasonality") ax[1].set_ylabel("Value") _ = ax[0].legend(loc=0) _ = ax[1].legend(loc=0) fig.tight_layout(pad=2.0) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.687 seconds) .. _sphx_glr_download_auto_examples_forecast_plot_holt_winters_predictor.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_holt_winters_predictor.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_holt_winters_predictor.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_holt_winters_predictor.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_