Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 28 ยท Projects

Project: Sales Forecast

Forecast monthly sales end to end with Statsmodels: decompose the series, build baselines, fit Holt-Winters and SARIMAX, compare with rolling-origin validation and report intervals.

A retailer needs a 12-month sales forecast to plan inventory and staffing. You will build it the way a careful analyst would: understand the series, set baselines to beat, fit two serious models, compare them honestly with a rolling validation and finish with a forecast that includes uncertainty.

The data are simulated monthly sales for six years: a rising trend, a yearly cycle with a strong December peak, and noise.

Step 1: look at the series

Python Create and decompose the series

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 decomposition recovers the December peak and a steady upward trend. The residual standard deviation (around 3) is the noise floor: no model can beat it on average.

Step 2: baselines

Before fancy models, measure two trivial forecasts on the last 12 months, which we hold out. The seasonal naive forecast repeats the same month of last year; the drift version adds the average year-over-year growth.

Python Baseline forecasts

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.

Anything we build must beat these numbers to justify its existence.

Step 3: Holt-Winters and SARIMAX

Python Two models on the same 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.

Both models should land near the noise floor, clearly below the baselines. If you could find only one holdout year to judge them, you would risk choosing by luck. Use several.

Step 4: rolling-origin validation

Fit on the first part, forecast the next 12 months, then move the origin forward a few months and repeat. Averaging across origins is a far more reliable comparison than one split.

Python Rolling-origin comparison

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.

Both real models beat the seasonal naive baseline at every origin, and they are close to each other. When two models tie, choose the simpler one or the one whose uncertainty you can describe best. SARIMAX provides likelihood-based intervals and AIC, so we use it for the final forecast.

Step 5: diagnose and forecast with intervals

Python Residual check and the 12-month 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.

A large Ljung-Box p-value says the residuals look like noise. The note about summed bounds shows a common trap: adding monthly interval bounds overstates the uncertainty of the yearly total, because monthly errors partly cancel. If you need an interval for the total, simulate paths (res.simulate(...)) and sum each path.

What to deliver

  • A chart of history, forecast and interval, and a table of monthly numbers.
  • The comparison against baselines using rolling-origin RMSE.
  • Assumptions: the seasonal pattern and trend continue; no promotions or shocks are modeled. Mention extensions such as an exog promotion calendar (Exponential Smoothing and SARIMAX).
  • A plan to refit every month and track forecast error.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Why compute baselines such as the seasonal naive forecast?

    Baselines show what is achievable without a model, putting model performance in context.
  2. 2. What is the advantage of rolling-origin validation?

    Averaging across origins reduces the chance that one lucky or unlucky period decides the comparison.
  3. 3. Why is summing monthly 95% interval bounds a poor interval for the yearly total?

    Independent errors do not all fall at their extreme together; simulate paths to get a proper interval.

Summary

  • Decompose, set baselines, fit Holt-Winters and SARIMAX, compare by rolling-origin RMSE.
  • Check residuals with Ljung-Box and always show forecast intervals.
  • Document assumptions and plan to refit as new data arrives.

Next: Practice Exercises