Retail

Demand forecasting with machine learning: a retailer’s guide

· 5 min read · By YLinkTech

Demand forecasting with machine learning means training one model across many products and stores, using sales history plus drivers such as price, promotions and calendar events, to predict how much of each item will sell. It tends to beat traditional per-item methods when you have many related series and good records of what drove past demand. It does not rescue poor data, so most of the work is in the inputs, the evaluation and the link to replenishment decisions.

When machine learning beats simpler methods

The strongest public evidence comes from the M5 forecasting competition, which used Walmart data. The organizers’ results paper, published in the International Journal of Forecasting in 2022, reports that entrants had to forecast 42,840 time series of hierarchical unit sales. LightGBM, a decision-tree-based method, was used by all of the top 50 competitors. The winning entry was an equal-weighted combination of six models.

The authors draw two lessons that matter for retailers. First, “cross-learning”, where a single model learns from many series at once, improves accuracy and helps with items that have short histories. Second, machine learning methods handle explanatory variables such as prices and promotions well. They also caution that firms should weigh the extra cost of running these methods against the accuracy gained.

That caution is the practical test. Machine learning is likely to pay off when you have thousands of item and location combinations, frequent promotions or price changes, and many slow or new items. A simple seasonal method may be enough when you have few products, stable demand and long histories.

The data you need

Model choice matters less than the inputs. Before you compare algorithms, check that you hold the following, at the level where decisions are made:

  • Sales history by item, location and day or week, ideally covering at least two full seasonal cycles.
  • Availability records. Sales are not demand. When a product was out of stock, recorded sales understate what customers wanted, and a model trained on them will learn to under-forecast.
  • Prices and promotions, including the planned future calendar, with the mechanics of each offer.
  • Calendar events such as holidays, paydays, school terms and local events.
  • Product and store attributes such as category, brand, pack size, store format and region, which let the model share learning across similar items.
  • Assortment changes: launches, delistings, substitutions and store openings.
  • External drivers such as weather, where they clearly move sales in your categories.

The common gap is not volume. It is the business decisions that were never recorded, such as an extra display or a local price change. Start logging them now, even if the model comes later.

Methods compared

Method How it works Fits well when Watch for
Seasonal naive and moving averages Repeats the last season or averages recent periods You need a baseline, or demand is stable Cannot react to promotions or price changes
Exponential smoothing and ARIMA A statistical model fitted to each series Long, regular histories and few external drivers One model per item is hard to maintain at scale and weak for new items
Gradient-boosted trees such as LightGBM One model trained across all series, with lags, prices, promotions and attributes as features Many related items with rich driver data Depends on feature engineering, and can leak future information if features are built carelessly
Deep learning models Neural networks trained across all series Very large datasets and teams with the skills to run them Higher compute cost and harder to explain to planners

Combining models is a reasonable default. The M5 winner did exactly that.

How to measure forecast accuracy

Many projects go wrong at evaluation. The online textbook Forecasting: Principles and Practice gives the ground rules.

  • Test on data the model has not seen. Accuracy can only be judged on new data, not on how well the model fits its training set. The book suggests a test set that is typically about 20% of the sample and at least as long as the longest horizon you need.
  • Be careful with MAPE. Percentage errors are infinite or undefined when actual sales are zero and extreme when they are close to zero. In retail, many item and store days are zero.
  • Use scaled errors to compare across items. Scaled errors, proposed by Hyndman and Koehler in 2006, measure each forecast against a naive forecast on the same series, so results are comparable between fast and slow sellers.

Add two checks of your own. Measure bias, because a forecast that is consistently high or low costs more than one that is noisy. Measure at the level where the decision is made, because a forecast that looks accurate by category can still be poor for a single store.

Common pitfalls

  • Information leakage. Using values at training time that will not be known when you forecast, such as actual weather or unplanned promotions.
  • Forecasting sales, not demand. Ignoring stockouts bakes past availability problems into future orders.
  • No baseline. Without a naive benchmark, you cannot tell whether the model adds value.
  • Point forecasts only. Safety stock depends on the range of likely outcomes, so inventory teams need quantiles, not a single number.
  • New products. Items with no history need attribute-based forecasts or a comparison to similar products.
  • No feedback loop. Planners override the forecast, the overrides are not recorded, and nobody learns whether they helped.
  • No monitoring. Demand patterns shift, so accuracy needs tracking and the model needs retraining on a schedule.

Rolling out demand forecasting with machine learning

  1. Pick one decision to improve, such as store replenishment for one category, and define the horizon and level it needs.
  2. Build the dataset, including availability and promotion history, and fix the worst data gaps.
  3. Set a baseline with a seasonal naive forecast and your current process.
  4. Train a gradient-boosted model across all items, and test it on held-out periods that include a peak.
  5. Run it in parallel with the current forecast for several cycles, and compare accuracy, bias and inventory outcomes.
  6. Connect the forecast to ordering, with planner overrides recorded.
  7. Monitor, retrain and extend to the next category.

Before you start, the AI readiness assessment checklist helps you test whether data and ownership are in place. If you are comparing a packaged planning tool with a custom model, use the build vs buy framework.

How YLinkTech helps

We help retailers and consumer brands move from spreadsheet forecasts to models that planners trust. Our AI and Data practice builds the data pipelines, trains and evaluates the models through our machine learning engineering work, and connects the output to replenishment and planning systems. We start with a baseline and a single category, so you see evidence before you scale. Contact us to discuss your forecasting problem.

Frequently asked questions

How much data do you need for machine learning demand forecasting?

There is no fixed threshold. What helps most is history across many related items and locations, ideally covering at least two seasonal cycles, together with records of prices, promotions and stock availability. A model trained across all items can forecast products with short histories by learning from similar ones.

Which machine learning model is best for retail demand forecasting?

Gradient-boosted trees are a strong starting point. In the M5 competition on Walmart sales data, LightGBM was used by all of the top 50 entrants, and the winner combined six models. Always compare against a simple seasonal baseline, because the best method depends on your data, horizon and level of detail.

Why is MAPE a poor accuracy measure for retail forecasts?

MAPE divides the error by actual sales, so it is undefined when sales are zero and extreme when they are close to zero. Many items sell nothing on a given day in a given store. Scaled errors, which compare each forecast with a naive forecast on the same series, are more reliable across fast and slow sellers.

Sources

This article is general information, not professional advice. See our Disclaimer.

Tell us what you are trying to build.

A 30-minute call is usually enough to know whether we are the right fit. We reply within one business day.