Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 28 ยท Time Series

Exponential Smoothing and SARIMAX

Forecast seasonal data with Holt-Winters exponential smoothing and SARIMAX in Statsmodels, add exogenous regressors, compare models on a holdout and read the forecasts.

Real series usually have a trend and a repeating season. This lesson shows the two workhorse tools for that case. Exponential smoothing builds forecasts from weighted averages that give recent observations more weight. SARIMAX extends ARIMA with a seasonal part and with exogenous regressors (outside variables such as price or temperature).

Python Create the monthly series used below

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Holt-Winters exponential smoothing

The Holt-Winters method maintains three running quantities: a level, a trend and a seasonal pattern, each updated with a smoothing weight. Statsmodels provides ExponentialSmoothing (classic) and ETSModel (a full state-space version with likelihood, AIC and prediction intervals). Choose additive seasonality when swings stay the same size, multiplicative when they grow with the level.

Python Holt-Winters forecast with a holdout

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Always compare against a naive baseline (here: repeat last year's values). A fancy model that cannot beat a naive one is not worth its complexity.

SARIMAX

SARIMAX(endog, exog, order=(p,d,q), seasonal_order=(P,D,Q,s)) adds a seasonal ARIMA component with period s. A common starting point for monthly data with a stable annual pattern is order=(1,1,1) and seasonal_order=(0,1,1,12): first differencing for the trend, seasonal differencing for the yearly pattern, and one moving-average term for each.

Python SARIMAX seasonal forecast

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Most actual values should fall inside the 95% band, a sanity check that the uncertainty is realistic.

Exogenous regressors

If an outside variable influences the series (price, weather, promotions), pass it as exog. You must supply its future values when forecasting, so use variables you can know in advance (a planned promotion calendar) or forecast them separately.

Python SARIMAX with a promotion indicator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The promo coefficient quantifies the lift: how much a promotion adds to the monthly level once trend and season are accounted for.

Choosing between the two

Situation Reasonable choice
Short series, clear trend and season, need quick forecasts Holt-Winters / ETSModel
Need intervals from a likelihood, model comparison by AIC ETSModel or SARIMAX
Outside drivers (price, weather, promos) SARIMAX with exog
Complex dependence structure, differencing needs SARIMAX

Residual checking from ARIMA Models applies equally here: look at res.plot_diagnostics() and Ljung-Box. Multiple related series can be modeled jointly with the vector autoregression (statsmodels.tsa.api.VAR).

Use time-series cross-validation (rolling origin): fit on the first part, forecast the next block, move the window forward and repeat. One holdout block can be luck.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does seasonal_order=(0, 1, 1, 12) mean in SARIMAX?

    The tuple is (P, D, Q, s): seasonal AR, seasonal differences, seasonal MA, and the season length.
  2. 2. What do you need to supply when forecasting with exogenous regressors?

    The model needs exog values for every forecast step, so use drivers you will know in advance.
  3. 3. Why compare against a naive baseline?

    A complex model must beat a simple benchmark to be useful.
  4. 4. When is multiplicative seasonality appropriate?

    Multiplicative seasonality scales the pattern with the level; additive keeps the swing constant.

Summary

  • Holt-Winters smooths level, trend and season; use ExponentialSmoothing or ETSModel.
  • SARIMAX adds seasonal terms and exog regressors to ARIMA.
  • Always evaluate on a holdout and compare to a naive baseline.
  • Exogenous drivers need known future values.

Next: Mixed-Effects Models