Skip to main content

15. Machine Learning for Demand Forecasting

Teaching rewrite — the Baseline model step. Original wording; illustrative numbers. Competition figures recomputed from the published scores.

Introduction​

Statistical models (lesson 14) apply predefined equations: give a non-seasonal model a seasonal product and it mistakes the cycle for changing trends; give a seasonal model a flat product and it invents seasonality. Machine learning (ML) works the other way round: a learning algorithm discovers relationships between inputs (history, drivers) and outputs (future demand) from data.

This lesson covers:

  • What ML is — and isn’t — and how it learns from features
  • Feature engineering as a business activity
  • Local vs global models
  • Black box vs white box, and how to peek inside (feature importance, scenarios)
  • Tree-based models and neural networks, with a short history
  • Realistic expectations from forecasting competitions and practice
  • How to launch an ML initiative — and four pitfalls

15.1 What is machine learning?​

flowchart LR
subgraph Statistics
D1[Data] --> M1[Predefined model] --> F1[Forecast]
end
subgraph Machine learning
D2[Data] --> L[Learning algorithm] --> M2[Learned model] --> F2[Forecast]
end

You choose the algorithm and its settings, but not the resulting relationships — the model learns them from a training dataset, then applies them to new data.

Statistical modelsMachine learning
ExplainabilityWhite boxBlack box
ComplexitySimplerMore complicated
Demand driversHard to includeEasy to include
Data requirementLimitedExtensive
Expected accuracyLowerHigher

Neither replaces the other — they trade transparency for flexibility.

What counts as ML here

Tree-based models (random forests, gradient-boosted trees) and neural networks. Linear regressions (including Lasso/Ridge/ElasticNet), ARIMA, and Prophet are treated as statistical models — be wary of vendors relabelling them as ML. Be even warier of “AI” claims: the term has no strict definition and often sells over-promises.

Features​

A feature is a piece of information the model can use to predict, e.g. “last quarter’s demand”, “next quarter’s price”, “promotion next quarter?”, “brand”.

BrandDemand Q−4Q−3Q−2Q−1Avg pricePrice Q+1Promo Q+1Demand Q+1 (target)
Low cost1,5005004003001010—200
Premium5001,0007505003530−15%700
Regular2503501504002020−20%300

(This is supervised learning: the model sees inputs and the desired output.)

Two success factors:

  1. The features you provide — business insight matters most. You can’t predict Black Friday sales without knowing whether the item will be discounted.
  2. Tuning the algorithm — a data-science skill.

Feature engineering is a business process​

Don’t leave data scientists alone. Run a brainstorm: “If I had to forecast next month myself, what would I want to check?” Typical answers become features:

  • Current price, and did it change recently?
  • Average monthly demand?
  • Was it recently out of stock?
  • Is a promotion running?

Then the hard part: collecting the data. Trade off quality vs availability — don’t freeze a project for months to collect a barely useful driver.

Local vs global models​

Local (typical statistical)Global (typical ML)
Trained onOne item’s history at a timeAll items at once
More history helps?YesYes
More items helps?NoYes — more examples of each pattern
Transfer learningNoneA never-promoted item can benefit from what promotions did to other items
Small datasetsWorksStruggles — too few examples

A global model learns general patterns (“promotions lift demand”, “recent growth tends to continue”); it learns cross-item relationships only if you give it features describing them.

Opening the black box​

ML won’t tell you level, trend, or seasonality. Two tools help:

  • Feature importance (tree models) — shows which features the model relies on, not how they affect demand. Useful to drop useless drivers (weather at 0.01% importance). If a driver you consider critical scores low, suspect bad data or a design flaw.
  • Scenario analysis — run the model with and without a driver (e.g. with/without a discount) and compare. Example: a promotion scenario shows +17% total uplift and dips before/after the promotion (self-cannibalisation).

Checkpoint: ML fundamentals​

Quiz

Checkpoint — section 15.1

1 / 4

What distinguishes ML from statistical forecasting models?

Pick an answer to see if you are right.


15.2 Main types of learning algorithms​

Technical extra — skip to 15.3 if you only need the business view.

A short history​

YearMilestone
1940sMcCulloch & Pitts model artificial neurons
1957Rosenblatt’s Perceptron (first trainable neural network); Holt’s exponential smoothing
1960Winters adds seasonality to exponential smoothing
1963Morgan & Sonquist: first decision tree algorithm
1985Damped trends for exponential smoothing (Gardner & McKenzie)
1986Backpropagation popularised — deeper networks trainable
1995–2001Boosting (AdaBoost 1995/97), random forests (2001)
2010–2015ReLU activation, Adam optimiser — deep networks train well
2016–2017XGBoost, LightGBM — fast, accurate gradient boosting

Why the boom only recently? Computing power and data grew, but the decisive factors were better algorithms (2010–2017) and simpler tools (open-source libraries, learning resources).

Tree-based models​

A decision tree asks yes/no questions (nodes) until it reaches a prediction (leaf) — like the game Guess Who?. The training algorithm picks, at each node, the question that splits the data into the most homogeneous groups. (“Does the person wear clothes?” is useless — everyone does.)

Example path for a forecast:

flowchart TD
A{Demand Q−1 > 300?} -- yes --> B{Average price > 20?}
A -- no --> X[Predict 150]
B -- no --> C{Price Q+1 < 25?}
B -- yes --> Y[Predict 650]
C -- no --> Z[Predict 550]
C -- yes --> W[Predict 420]
  • Random forest — averages hundreds of independent, randomised trees; simple and robust.
  • Gradient boosting — builds trees one after another, each focusing on the previous trees’ mistakes; today’s top performers (XGBoost, LightGBM).

Neural networks​

An artificial neuron weights its inputs and applies an activation function (often something like a capped weighted sum, e.g. ReLU) to produce an output.

flowchart LR
I1[Demand Q−2] --> H1((h))
I2[Demand Q−1] --> H1
I3[Discount] --> H2((h))
I4[Price] --> H2
I1 --> H2
I4 --> H1
H1 --> O1[Forecast P1]
H1 --> O2[Forecast P2]
H2 --> O1
H2 --> O2
  • Input layer passes features in; hidden layers do the learning; output layer produces forecasts (one neuron per period).
  • Training = an optimiser adjusts the connection weights to reduce error.

15.3 What to expect from ML​

Forecasting competitions​

CompetitionYearGranularityItemsHorizonBenchmarkBenchmark scoreWinnerError reduction
Corporación Favorita2018Store × product × day210,00016 daysSeasonal naïve0.84860.509240%
M5 (Walmart)2020Store × product × day42,84028 daysExponential smoothing0.67100.520422%
Intermarché2021Store × product × day275,78190 daysSeasonal moving average0.60880.547810%

Error reduction = (benchmark − winner) / benchmark. All three were won by ML. Gains differ partly because of the benchmark (a weak seasonal naïve flatters Favorita) and the data/metric (Intermarché had one year of history and a log-scaled metric). Each used a different metric, so compare cautiously.

Rules of thumb from practice​

  • ML typically reduces forecast error by 0–30% versus a good moving average.
  • Gains grow with more data — shortages, promotions, prices; promotions alone can be worth up to ~15%.
  • ML shines most on granular data.
  • Claims far beyond this deserve scrutiny — check for cherry-picked periods or excluded “worst” items.

Improving the baseline, not replacing planners​

ML may not beat your whole process (planners know things the model doesn’t), but it should beat your baseline — freeing planners to focus on new products and items where they have special information.

StepBefore: MAE (FVA)BiasAfter ML: MAE (FVA)Bias
Benchmark52%−1%52%−1%
Baseline model45% (+7)−3%41% (+11)−2%
Demand planners41% (+4)+1%39% (+2)+1%

The final forecast improves from 41% to 39%, and planners need to add less — less workload.


Checkpoint: algorithms and expectations​

Quiz

Checkpoint — sections 15.2 and 15.3

1 / 4

How does gradient boosting differ from a random forest?

Pick an answer to see if you are right.


15.4 Launching an ML initiative​

Follow the 5-step framework (objective → data → metrics → baseline model → review). For ML, the model-building loop gains a step:

flowchart LR
A[Visual data analysis] --> B[Model selection] --> C[Feature selection] --> D[Parameter optimisation] --> E[Error analysis] --> A

Four pitfalls​

PitfallAvoid it by
Bad test set-upHold out a test period never used for feature selection or tuning (e.g. tune on 2021–2025, test on 2026). Picking the best of many models on the same period you report is cherry-picking. Compare against a benchmark, your current engine, and your consensus — same periods, same granularity
“What” before “why”Don’t chase fashionable models. Fix the objective (level, horizon), the data (demand, not sales), and the metrics (MAE + bias, not MAPE) first
Wrong expectationsPromise too much → disappointment and user resistance; too little → no traction. Plan for 0–30%; >15% is realistic when promotions or pricing drive demand
“We tried ML once”ML is hundreds of models and set-ups. One failed attempt doesn’t prove ML can’t work — any more than one failed spreadsheet proves maths doesn’t

Rank: ML project​

Quiz

ML project sequence

1 / 2

Rank the steps of an ML forecasting project.

OrderDrag the handle to rearrange — top should be first.

  1. 1Agree metrics (MAE + bias, value-weighted) and benchmarks.
  2. 2Collect demand data and key drivers (promotions, prices, shortages).
  3. 3Select features and tune models on a training period.
  4. 4Evaluate on an untouched test period against benchmark, current engine, and consensus.
  5. 5Deploy as the baseline; track FVA.
  6. 6Define the decision-level objective (granularity, horizon).

Drag items into the correct order (or use ↑↓), then check.


Check: machine learning​

Quiz

Machine learning for demand forecasting

1 / 5

Which model is a typical example of ML in this lesson?

Pick an answer to see if you are right.


Takeaways​

Remember
  • ML learns relationships from data; statistical models assume them
  • Features drive success — make feature engineering a business exercise
  • Global models learn across items; need enough data
  • ML is a black box — use feature importance and scenarios
  • Expect 0–30% error reduction vs a good benchmark; more data (promotions, prices, shortages) → bigger gains
  • ML improves the baseline and reduces planner workload; it doesn’t replace planners
  • Test honestly on held-out periods; follow the 5-step framework

Further Reading​