Contents/ Part XXIII · Forecasting Case Study/ Chapter 141

Case Study: Forecasting with Drivers

A pure time-series model forecasts the future only from the past of the series. But real demand responds to things you already know: the weather, your promotions, the holiday calendar. SARIMAX feeds those drivers into the forecast, and here it cuts the error in half.

⏱️ ~22 min read
🐍 Full notebook included
📊 Chapter 141

Classic forecasting models, ARIMA and its seasonal cousins, predict tomorrow purely from the history of the series itself. That is powerful, but it is blind to information you often have in hand: a promotion you have scheduled, a heat wave in the forecast, a public holiday next week. SARIMAX, ARIMA plus eXogenous drivers, lets the model use that outside information. It is also called regression with ARIMA errors, and it turns a forecast into something you can plan against.

📈
SARIMAX adds exogenous regressors (drivers) to a seasonal ARIMA model. The drivers' coefficients are interpretable, but there is a catch: to forecast the future you must supply the future values of the drivers, so it works best when they are known or plannable in advance.
🎯
What this case study ties together

It extends the time-series toolkit of Parts XXII–XXIII with external drivers: a proper temporal train/test split, a seasonal-naive baseline, a SARIMAX model whose driver coefficients are read like a regression, residual diagnostics, and the honest reality that forecasting forward means forecasting the drivers too.

1

The Forecasting Problem, and the Data (Steps 1–2)

A store needs a daily forecast of units sold, to stock shelves and plan staffing. We have two years of daily data, 730 days averaging about 238 units, along with the drivers the business knows or plans: the day's temperature, whether the product was on promotion, and whether it was a holiday. The goal is a forecast that uses those drivers, not just the calendar.

📂 Dataset · case-study-forecasting-with-drivers--daily_demand.xlsx

One row per day (no gaps): units_sold (the target), temperature_c, on_promotion (0/1), is_holiday (0/1), and day_of_week. Ninety-five promotion days and twenty-four holidays over the two years.

2

The Rhythms, and the Shocks (Step 3)

Three patterns stand out, and each points to a driver. A smooth yearly swing (demand rises with temperature, correlation about 0.55), a strong weekly rhythm (weekends far higher), and sharp upward spikes on promotion days. A pure ARIMA can learn the first two from the shape of the series. But the promotion spikes are effectively random from the series' own point of view, the only way to anticipate them is to feed the model the promotion calendar.

A pure time-series model cannot see a promotion coming demand promotion spikes the promotion calendar (known in advance) is exactly what SARIMAX feeds the forecast smooth seasonal + weekly rhythm: ARIMA can learn this
3

Two Models: With and Without the Drivers (Steps 4–8)

4–5

A temporal split, and a tough baseline

For time series you never shuffle: we train on the first ~640 days and hold out the final 90 days. The seasonal-naive baseline, repeat the value from the same weekday a week ago, is genuinely hard to beat on weekly data; it is off by about 23 units a day.

6–8

Calendar-only, then calendar plus drivers

A first SARIMAX knows the weekly rhythm (day-of-week terms) and a day-to-day carryover (an AR(1) term), but not the business drivers. It scores about 28, a touch worse than naive, because it cannot see the weather warming or a promotion coming. Add the three drivers and the error collapses to about 11.5 units (MAPE near 5%), cutting the daily error roughly in half versus the baseline. Same machinery, same horizon; the only change is the information the model can see.

Average daily error (MAE) on the 90-day holdout MAE0 23.3 seasonal-naive 27.7 calendar-only 11.5 SARIMAX + drivers half the error
The 90-day holdout: the actual demand line, a calendar-only forecast that misses every promotion spike, and the SARIMAX-with-drivers forecast that rides on top of the actual line, catching the spikes marked as promotion days
From the notebook · Step 8
The calendar-only forecast (amber) tracks the weekly wiggle but sails past every promotion spike; the driver model (blue) rides on top of the actual line, because it was told when the promotions happen.
4

Reading the Drivers (Steps 9–10)

Because SARIMAX is a regression, its driver coefficients are directly interpretable, with confidence intervals. Each degree Celsius warmer adds about 2.7 units; a promotion adds about 59 units a day; a holiday about 32. All three are overwhelmingly significant and their intervals are tight. A pure ARIMA gives you a forecast; SARIMAX gives you a forecast and a quantified reason for it.

The residual diagnostics are clean, no trend, no seasonal ripple, tiny autocorrelation, and the AIC drops sharply versus the calendar-only model. In full honesty, with 640 observations the Ljung-Box test is powerful enough to flag a whisp of leftover autocorrelation (p near 0.001); it is practically negligible, but a production model might add a second AR lag to tidy it up. Diagnostics matter even when the forecast is already good.

5

Forecasting Forward, and the Memo (Steps 11–12)

Here is the crucial difference from a pure ARIMA. To forecast tomorrow, SARIMAX needs tomorrow's driver values. Two of ours are known in advance, the promotion schedule and the holiday calendar are things the business plans, but temperature must itself be forecast. So we build a future scenario: planned promotions and holidays, plus a temperature outlook. Uncertainty in the weather becomes uncertainty in the demand, which the prediction interval reflects.

A 14-day-ahead forecast with a 95% prediction interval; two planned weekend promotions appear as clear upward bumps in the forecast line
From the notebook · Step 11
A 14-day forecast under a planned-promotion scenario. The planned promotion days show up as clear bumps, the model turns a marketing plan into a demand number operations can stock against; the shaded band is the 95% interval.

Memo to the operations team

We built a daily demand forecast that uses the information you already plan around, the promotion schedule, the holiday calendar, and the weather outlook, on top of the normal weekly rhythm. On the most recent three months it predicted demand to within about 5% on an average day, roughly half the error of a model that ignores those drivers.

What the drivers are worth

A promotion adds about 59 units a day, a holiday about 32, and each degree of warmth about 2.7, all measured with tight confidence intervals.

The catch

To forecast ahead we must supply the future drivers, so a promotion plan and a weather outlook are inputs, not outputs. The forecast is only as reliable as those assumptions, and the interval widens when the weather is uncertain.

Recommendation

Use it for stocking and staffing, and refresh it whenever the promotion plan changes.

🐍

Run the whole forecast in Python

The companion notebook is the full 12-step SARIMAX workflow: it explores the weekly and yearly rhythms, makes a temporal train/test split, sets a seasonal-naive baseline, fits a calendar-only model and then a model with the three drivers, compares them on a 90-day holdout, reads the driver coefficients with confidence intervals, checks the residual diagnostics, and builds a forward forecast under a planned-promotion scenario, all library-first with statsmodels.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly. Open in Colab runs it live. To run locally, install numpy, pandas, matplotlib, statsmodels, and openpyxl.

🎓 Key Takeaways

  • Drivers beat the past alone: SARIMAX cut the daily error roughly in half (MAE 23 → 11.5) by using promotions, weather, and holidays.
  • The calendar is not enough: a model that knew only the weekly rhythm barely matched the naive baseline, it could not see the spikes.
  • Split by time, never shuffle: a temporal holdout is the only honest test of forecasting into the unknown.
  • Coefficients are the payoff: a promotion is worth about +59 units, a holiday +32, each degree +2.7, a forecast and its reasons.
  • You must forecast the drivers too: planned drivers are pure gain; predicted ones (weather) import their own uncertainty into the interval.
6

Take It Further

Five ways to stress-test and extend the forecast in the companion notebook:

1

Search for the ARIMA order

Fit a grid of (p,d,q) orders and let AIC pick the error model, then compare to the holdout score.

Hint: loop the orders with the same drivers, sort by AIC; trust the holdout when they disagree.
2

The cost of an imperfect weather forecast

Re-score the holdout using a seasonal-normal temperature instead of the true one, and measure the penalty.

Hint: swap the temperature column in the test exog, compare MAE.
3

Plan a promotion calendar

Compare two future promotion schedules and read off the total forecast demand for each.

Hint: build future exog with different on_promotion patterns; watch for the missing interaction.
4

Do the prediction intervals hold up?

Check the empirical coverage of the 95% interval on the held-out days.

Hint: get_forecast(...).conf_int(), count how many actuals fall inside.
5

Rolling-origin cross-validation

Slide the cutoff forward over several origins and confirm the drivers win at each, not just once.

Hint: refit and forecast a fixed horizon at each origin, average the errors.
📓

All five, worked in a companion notebook

A second notebook, Take It Further, rebuilds this chapter's forecast and works every extension with visuals and explanations: an AIC order search, the weather-forecast penalty, a promotion-calendar planner, a prediction-interval coverage check, and rolling-origin cross-validation.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub
7

Quiz: Test Yourself

Eight questions on driver-based forecasting, from the temporal split to the future-driver catch. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved.

➡️
Up next

That completes the case studies. Advanced & Applied Topics now opens with Bayesian Inference in Practice: prior times likelihood gives a posterior, and from it flow credible intervals, MLE versus MAP, MCMC, and honest probabilities like “B beats A.”