Blog / ML & Forecasting
ML & ForecastingDemand Forecasting Methods: From Statistics to Machine Learning
How the main demand forecasting methods work, when each one fits, and how to choose by history, series count, horizon and the cost of an error.
Find a starting method
How many series do you forecast?
Do promotions, prices or weather move sales?
Do many items go days without a sale?
Do you plan at several levels (store, region, network)?
Start with
Gradient boosting on features
One model learns from every series at once and takes promotions, prices and weather as features.
Benchmark it against the seasonal naive forecast.
Read about this methodDemand forecasting estimates how much of each item customers will buy over a given period, so the business can plan orders, stock, staff and promotions. Which demand forecasting method fits depends on four things: how much history you have, how many series you forecast (item × store quickly runs into tens of thousands), the horizon, and which mistake costs more, forecasting too low or too high. For a few hundred series with steady seasonality, exponential smoothing or ARIMA is usually enough. For tens of thousands of series whose sales move with promotions and prices, gradient boosting on features works better. Neural networks pay off at large volumes and long horizons. Whatever you choose, compare it with a naive forecast first.
The charts below run on synthetic series and compute every number in your browser, so you can change a parameter and watch what a method does. Figures from our own projects are marked and link to the page that publishes them.
Types of demand forecasting: qualitative and quantitative methods
Demand forecasting techniques fall into two groups. Qualitative methods rely on judgement: expert opinion, the Delphi method, sales-team estimates and market research. They lead when there is no comparable history, for example a new category or market, and they stay useful for adjusting a forecast to news the data hasn’t seen yet. Quantitative methods learn from data: time series forecasting methods use a series’ own past, and causal or machine learning methods add the drivers of demand such as price, promotions and weather.
This guide covers the quantitative methods, from simple baselines to statistical forecasting and machine learning, because they are what runs every day across thousands of items and stores.
A baseline to beat
Before choosing a model, you need a point of reference. The naive forecast says tomorrow sells what today sold. For seasonal demand, the seasonal naive forecast says this Saturday sells what last Saturday sold. A moving average of the last few weeks works too.
These forecasts take a minute to build, and on short, stable series they’re hard to beat. If a complex model can’t beat the seasonal naive forecast in a backtest, stop developing it.
A backtest should run the way the model will run in production. Train on data up to a date, forecast the following weeks, move the date forward and repeat. This is a rolling-origin backtest, also called time series cross-validation. Splitting a series at random doesn’t work: the model sees the future and reports an accuracy it won’t have later.
How to split a series for a backtest
4 folds, each trained only on the past
- Training days
- Test days
- Not used yet
Each fold forecasts days the model has never seen. In the random split, test days land between training days, and the model has already seen what came after them.
Statistical forecasting methods
Exponential smoothing: ETS and Holt-Winters
The forecast is a weighted average of past sales in which recent weeks count more than older ones. Holt-Winters forecasting adds a trend and a seasonal pattern. ETS is the name for the whole family; forecasting libraries pick the best member for each series automatically.
α is the smoothing weight, between 0 and 1. A sale k days old gets weight α(1 − α)k, so at α = 0.3 half of the total weight sits on the last two days.
Smoothing fits when you have few series, steady seasonality and at least two full seasonal cycles of history: a few weeks for a weekly pattern, two years for a yearly one. It runs fast, and a planner can see where the number came from. It doesn’t see external factors, so a promotion or a price change passes it by.
One series, five methods, the last four weeks held out
Seasonal naive: WAPE 8.7%
- MAPE
- 8.9%
- WAPE
- 8.7%
- Bias
- −4.2%
- WAPE against seasonal naive
- the baseline itself
Every future day repeats the last known day.
Each day repeats the same weekday of the last week, m = 7.
A flat line at the mean of the last 14 days.
α = 0.30: half the weight sits on the last 2 days.
Level, trend and a weekly pattern, each smoothed with its own weight.
- Actual sales
- Forecast
- Seasonal naive, drawn under the other methods
- Held-out weeks
Holt-Winters beats the baseline here because it follows both the weekly pattern and the slow trend. With γ at 0 its weekly pattern stays at the first week’s shape, and the error grows.
ARIMA and SARIMA
ARIMA describes a series through its own past values and its past forecast errors; SARIMA adds seasonality. Feed it external variables such as price and promotion dates, and it becomes ARIMAX.
ARIMA suits the same problems as ETS and helps most when a series has strong autocorrelation. Each series is tuned on its own, which gets expensive and fragile across tens of thousands of them. Sharp promotion spikes are hard for ARIMA as well.
Prophet
Prophet splits a series into trend, seasonality and holiday effects, which makes it convenient when holidays drive sales.
Croston’s method for intermittent demand
Many items don’t sell every day: spare parts, rare sizes. On these series plain smoothing jumps after every sale and sinks between sales, so its forecast depends on the day you look. Croston’s method forecasts two things separately, the size of a sale and the interval between sales, and divides one by the other. Its TSB variant updates the chance of a sale every period, so the forecast fades when an item stops selling.
z̃ is the smoothed size of a sale, p̃ the smoothed interval between sales, π̃ the smoothed chance of a sale in a period. Croston updates z̃ and p̃ only on days with a sale; TSB updates π̃ every day.
Ten weeks of a slow-moving item
Next-day forecast: Croston 1.40, TSB 2.50, smoothing 2.96
- Croston, z̃ ÷ p̃
- 5.48 ÷ 3.93 = 1.40
- TSB, π̃ × z̃
- 0.46 × 5.48 = 2.50
- Simple smoothing
- 2.96
- Average daily sales, last 14 days
- 1.79
- Units sold
- Croston
- TSB
- Simple smoothing
With the stop after day 45 switched on, TSB drifts towards zero. Croston keeps forecasting sales that will never come: it only updates on days with a sale.
Use it for the long tail of the range, items that sell a few times a month. To set their stock, order at a quantile of a probabilistic forecast, as shown below.
Machine learning demand forecasting on features
Besides a series’ own history, a feature-based model gets outside data: the calendar and holidays, prices, promotions, weather, stock levels, sales of similar items. Each day of an item’s sales in a store becomes a row in a table, and the model learns from all the rows at once.
Linear regression
It’s a good place to start: you see straight away how many units a promotion or a weekend adds. Its effects simply add up unless you add interaction terms by hand. In practice the same discount lifts sales more on a hot day than on a rainy one, and a plain linear model won’t notice.
Add the drivers of demand one by one
WAPE 14.1% on the held-out weeks
- WAPE, held-out weeks
- 14.1%
- WAPE on promotion days
- 25.6%
- Promotion adds
- off
- Each °C adds
- off
- Each +1 in price changes sales by
- off
- Promotion on a hot day adds
- off
- Actual sales
- Model
- Promotion day
- Held-out weeks
Fitted by least squares on 24 weeks and scored on the last 4. Switched on in the order of the buttons, the error goes 14.1%, 11.7%, 12.3%, 6.1% and 5.4%. The promotion leaves the overall error almost where it was, since only three held-out days have one, yet it halves the error on those days, from 24.0% to 12.5%. The promotion × heat term then recovers what a hot-day promotion adds on top.
Gradient boosting: LightGBM, XGBoost, CatBoost
Boosting builds an ensemble of decision trees and finds interactions like discount × weather on its own. In the M5 competition on Walmart sales (42,840 series), most of the top solutions were built on LightGBM.
One model learns from many series at once, so a slow seller borrows patterns from fast ones and a new item gets a forecast from similar items. Around 24 months of sales history lets the model see the yearly cycle twice. It also needs features: sales over past days and weeks, rolling averages, the calendar, prices, promotions. In our experience the right drivers of demand sharpen the forecast, though a single driver can leave the overall error flat while fixing the days it touches, as the promotion does above.
Trees don’t extend a trend beyond the values they saw in training. For long horizons, model the trend separately, with a feature or by detrending the series first.
Neural networks and deep learning
LSTM, DeepAR, N-BEATS and the Temporal Fusion Transformer learn from thousands of related series at once. Many of them output a probabilistic forecast, a range rather than a single number. In the M4 competition (100,000 series), the winner was a hybrid of exponential smoothing and a recurrent neural network.
A neural network is worth considering when you have a great many series with long histories, a long horizon, and planners who need a range. It needs more data and compute than boosting, and its output is harder to explain, so compare it with boosting on the same data first.
Pretrained time series models such as Chronos and TimesFM were trained on large collections of other series and forecast without training on yours. They’re cheap to try as one more baseline.
Hierarchical forecasting, horizons and ensembles
Demand is planned at several levels: item in a store, category, region, the whole network. Forecasts built separately at each level disagree: the store forecasts don’t add up to the network forecast. Reconciliation fixes this. You can add forecasts up from the bottom, split the top one down by historical shares, or reconcile optimally with MinT, which combines all levels and trusts the less noisy ones more.
Three stores and their network, forecast separately
Stores sum to 920, the network says 980
- Stores add up to
- 920
- Network forecast
- 980
- Gap
- 60
- Historical shares
- 45%, 33%, 22%
S maps the stores to every level, W holds how noisy each forecast is. With equal trust (W = I) every node moves by the same amount, here gap ÷ 4 = 15.0.
Bottom-up keeps the stores and drops the network forecast. Top-down keeps the network and splits it by historical shares. OLS moves every node a little.
The horizon shapes the forecast too. Each planning cadence needs its own number, refreshed on its own schedule:
| Horizon | Forecast | Refreshed | Used for |
|---|---|---|---|
| Day | Next 14 days | Every morning | Store orders for tomorrow |
| Week | Next 8 weeks | Every Monday | Staff rosters and promotion stock |
| Month | Next 6 months | Every month | Supplier orders on their lead times |
| Quarter | Next 4 quarters | Every quarter | Volume commitments and warehouse space |
It helps when one demand model feeds all four and each team gets a number built for its own decision.
An ensemble combines the forecasts of several models by averaging or weighting them. Different methods make different errors that partly cancel, so a combination is usually steadier than any single model. For an energy company we forecast quarterly spend across the whole organisation with an ensemble of neural and statistical models. That’s spend rather than demand, but the method is the same, and aggregate accuracy is 94%, validated by backtest (see our cases).
Data for demand forecasting: stockouts, promotions and new items
Sales show demand only on days when the item was in stock. When the shelf runs empty, sales stop at whatever was on it, even though more shoppers came in. A model trained on those days as they are learns a demand that’s too low and orders even less next time. So mark the stockout days and restore demand for them.
Eight weeks of demand against the stock on the shelf
Sales understate demand by 8.2%
- Stockout days
- 27 of 56
- Average sales
- 41.3
- Average demand
- 45.0
- Restored estimate
- 45.6
- Units sold
- Sold out
- Demand (normally unseen)
- Restored estimate
- Stock
A stockout day only tells you demand reached the stock. The restored estimate fits a censored normal per weekday (an EM fit) and replaces each sold-out day with the demand expected above the stock. The lower the stock, the wider the gap between sales and demand. When nearly every day sells out, little is left to restore from, and the estimate drifts too.
Without a promotion calendar, a model takes a promo peak for seasonality and expects it again next year. Pass promotions, price changes and displays to the model as features.
A new item has no history, so its forecast comes from its category, price, brand and the sales of similar items in their first weeks.
Weather and local events sharpen the forecast where demand depends on them, fresh food and drinks for example. In one of our projects the forecast uses more than 120 factors and places replenishment orders itself, with a payback period of 9–12 months.
Forecast accuracy metrics and the cost of an error
MAPE, the mean absolute percentage error, is easy for the business to read. It breaks on days with zero sales and inflates the error on small volumes. It also punishes forecasting high harder than forecasting low: an under-forecast can’t cost more than 100%, an over-forecast can cost any amount, so a model tuned on MAPE drifts low.
WAPE divides the sum of absolute errors by total sales and holds up better on the long tail. Bias shows whether a model runs high or low on balance. Probabilistic forecasts are scored with the quantile (pinball) loss.
MAPE
WAPE
Bias
Pinball loss at quantile q
MAPE vs WAPE on a quiet day
How a quiet day moves MAPE and WAPE
MAPE 11.3%, WAPE 5.4%
- MAPE
- 11.3%
- WAPE
- 5.4%
- Bias
- −0.7%
- The quiet day’s share of MAPE
- 63%
WAPE = 16.0 ÷ 295 = 5.4%
- Actual sales
- Forecast
At zero sales on the quiet day MAPE can’t be computed, while WAPE only moves from 5.4% to 6.9%. Halve every forecast and MAPE reaches 46.9%: an under-forecast can’t push it past 100%. Double them and it reaches 112.5%, with no ceiling above.
Measure the error separately for each horizon and level. Tomorrow’s error for an item in a store and next quarter’s error for a category mean different things, and one blended number hides both.
Ordering at the right quantile: the newsvendor model
Missing low and missing high cost different amounts. Our AI Prediction page uses a yogurt as its example: a lost sale costs $0.62 in margin, and an unsold pot costs $0.29. Ordering at the median forecast costs more here: $68 a day in misses against $61 at the best order. The classic newsvendor model gives the profitable order: it sits at the quantile 0.62 / (0.62 + 0.29) ≈ 0.68, the level that demand stays below on 68% of days. The dearer a lost sale compared with a write-off, the higher the quantile. This needs a probabilistic forecast: a single number doesn’t tell you where the 68th percentile is.
cu is the cost of one unit short (the lost margin), co the cost of one unit over (an unsold pot), F the forecast distribution of demand.
How many pots of yogurt to order for one day
Order 1,217 pots: misses cost $61 a day, $68 at the median
- Quantile q*
- 0.68
- Order Q*
- 1,217
- Expected short
- 39 pots, $24
- Expected over
- 126 pots, $37
- Cost of misses
- $61 a day
- At the median, 1,129
- $68 a day
- Days demand stays below the order
- Profitable order
- Median forecast
- Expected cost of misses
Demand here is the forecast from our AI Prediction page: median 1,129 pots, 80% range 890–1,368. A dearer lost sale moves the order right, a dearer unsold pot moves it left.
A backtest shows accuracy on past data. The effect on money is checked with an A/B test on real revenue, which is how the +13% on our AI Prediction page was proven.
Which demand forecasting method when
| Method | Fits when | Doesn’t fit when | Data you need |
|---|---|---|---|
| Naive and seasonal naive | Always, as the baseline | As the final model when promotions or a trend drive sales | Any history |
| ETS, Holt-Winters | Tens to hundreds of series, steady seasonality | Sales move with promotions and prices | Two full seasonal cycles per series |
| ARIMA, SARIMA, ARIMAX | A few series with strong autocorrelation | Thousands of series, sharp promotion spikes | A regular series without gaps |
| Linear regression on features | A few hundred series where price and promotions matter | Effects interact, unless you add the terms by hand | History plus the drivers as columns |
| Croston, TSB | Many days without a sale | Items that sell every day | History including the zero days |
| Gradient boosting | Thousands of series, promotions, prices, new items | A long horizon with a strong trend, unless the trend is modelled separately | About 24 months of history and the drivers as features |
| Neural networks | Tens of thousands of related series, long horizons, a range is needed | Little data, or the forecast must be simple to explain | Long histories and compute |
| Ensembles and reconciliation | Planning at several levels and horizons | One series, one horizon | Forecasts from several models; for reconciliation, forecasts at every level |
Cheatsheet: how to choose a demand forecasting method
- Compute the seasonal naive forecast and its error. Every model has to beat it.
- Count your series. Up to a few hundred, start with ETS or ARIMA; with thousands, start with gradient boosting.
- Check whether promotions, prices and weather move sales. If they do, you need a feature-based model.
- Forecast the items with intermittent demand with Croston, TSB or a probabilistic model.
- If you plan at several levels, reconcile the forecasts.
- Price an under-forecast and an over-forecast, and order at the quantile they imply.
- Check the revenue effect with an A/B test. A backtest only shows accuracy.
Four of these questions are in the method finder at the top of the page.
FAQ
What is demand forecasting?
What are the main types of demand forecasting?
Which demand forecasting method is the most accurate?
How much sales history do you need for a forecast?
Is machine learning better than statistical forecasting methods?
How do you forecast demand for a new product?
How do you account for stockouts in sales history?
Which forecast accuracy metric should you use?
Further reading: Rob J Hyndman and George Athanasopoulos, Forecasting: Principles and Practice (3rd edition), free online.