How do you forecast demand with AI? Methods and accuracy in a grocery chain
Who it is forDemand planning and dispatch teams at grocery chains, category managers, buying and supply chain managers, data and IT leads
The demand forecast is the first line of every stock decision in a grocery chain: what goes from the warehouse to which branch, how much safety stock is held and how much is bought for a promotion all come from the same figure. In a chain with forty branches and six thousand active products, that figure is produced again every day for hundreds of thousands of product-branch rows and cannot be done by hand; this is where AI enters the conversation. This guide covers the level at which to forecast, what methods from the simplest to machine learning actually do, which variables go into the model, what the M5 forecasting competition really found about machine learning, how stockout days hide demand, how to measure accuracy with MAPE, WAPE and bias, and which rows a planner should review. Daily ordering of fresh food is covered in the fresh food demand forecasting guide, and how the forecast becomes a dispatch quantity in the guide on what AI does in store replenishment.
At what level should demand be forecast?
The forecast is made at the level where the decision is taken. Since dispatch from the warehouse is decided per product and branch, the forecast must also be at product × branch level; a forecast that is right for the chain total can leave the yoghurt shelf empty in one branch while filling the backroom in another. The time grain comes from how often the decision is made: a branch receiving three deliveries a week needs a daily forecast, one receiving a single delivery a weekly forecast; fresh food and bakery go down to the hour.
The finer the level, the noisier the series. Forecasting: Principles and Practice, one of the core textbooks of the forecasting literature, notes that bottom-level series can be quite noisy and more challenging to model and forecast, and asks for forecasts that are coherent across levels: branch forecasts must add up without contradicting the region and chain forecasts. A spice that sells two units a day in one branch sells none on some days and five on others; the chain total for the same product is a smooth curve.
The number of series multiplies with the level, too. The example below shows how many forecast figures a mid-sized chain produces every day. At this scale the planner's job is not to produce figures one by one but to pick out, from the figures the system produces, the ones that need review.
- Forecast figures produced per day
Number of branches × Number of active products × Forecast horizon (days)
| Level | Decision it serves | Who uses it | Typical difficulty |
|---|---|---|---|
| Chain × category × month | Budget, buying volume, warehouse capacity | Management, category team | Year-on-year comparison misleads in months the holidays move through |
| Branch × category × week | Staff planning, department space | Area and branch managers | A newly opened branch has no history |
| Product × warehouse × week | Supplier order | Buying | Lead time and minimum order quantity |
| Product × branch × day | Warehouse-to-branch dispatch and transfer | Dispatch planner | Intermittent sales, stockout days, promotion spikes |
| Product × branch × hour | Bakery batches, fresh counter replenishment | Branch and department lead | Intraday curve, the hour the shelf runs empty |
What does each method do: from the naive forecast to machine learning
Forecasting methods read like a ladder from simple to complex, and each rung has to beat the one below it. Forecasting: Principles and Practice uses the mean, naive, seasonal naive and drift methods not as methods of choice but as benchmarks: a new method that cannot beat these simple methods adds no value. For a grocery chain the most meaningful benchmark is the seasonal naive forecast; tomorrow's forecast is the sales on the same day last week. This simple rule is surprisingly hard to beat: only 35.8 per cent of the teams in the M5 competition managed to beat the seasonal naive method.
A moving average takes the mean of the last few periods and smooths the noise, but because it gives every past day equal weight it reacts late to change. Exponential smoothing solves this with weights: in the book's definition, the forecast is a weighted average whose weights decrease exponentially as observations come from further in the past. If the smoothing parameter α is close to zero the distant past dominates; if it is close to one the latest observation does. The organisers of the M5 competition also count the exponential smoothing family among the methods used as standards in retail sales forecasting for many years.
What these methods have in common is that they only look at the series' own history. A promotion week, a price change or a religious holiday sits in the series as a spike; the method does not know why and either takes the spike for seasonality or spreads it across the average. Regression with explanatory variables and machine learning are therefore the next rung: they explain demand from past sales together with variables such as promotions, price, calendar and weather. What sets machine learning apart from regression is that it can learn interactions between variables (a discount working differently in a holiday week, for instance) and non-linear relationships without them being defined by hand, and that it can learn from thousands of series with a single model.
- Naive
Forecast(t+1) = Actual(t)- Seasonal naive (daily data)
Forecast(t+h) = Actual(t+h−7)h at most 7 days; the same day last week.- Moving average
Forecast(t+1) = (Actual(t) + … + Actual(t−n+1)) ÷ n- Simple exponential smoothing
Forecast(t+1) = α × Actual(t) + (1 − α) × Forecast(t)α is the smoothing parameter between 0 and 1.
| Method | How it works | When it is enough | Weakness |
|---|---|---|---|
| Naive | Tomorrow's forecast is today's sales | As a benchmark | Does not see the day-of-week effect |
| Seasonal naive | Tomorrow's forecast is the same day last week | Benchmark for steady, non-promoted products | Repeats a single unusual day exactly |
| Moving average | Mean of the last n periods | Stable demand that changes rarely | Reacts late to change |
| Exponential smoothing | Average with weights decreasing exponentially into the past; trend and season can be added | Most steady products | Does not see the cause of promotions and holidays |
| Regression with explanatory variables | Demand = base + promotion, price and calendar effects | Product groups with few, known effects | Interactions are defined by hand |
| Machine learning (tree ensembles, neural networks) | Learns from thousands of series and variables with one model | Many series, frequent promotions, consistent records | Needs data preparation and validation discipline; the reasoning behind a figure is not visible by itself |
Which variables go into the forecast: promotions, price, holidays, weather, paydays
The organisers of the M5 competition write that time series methods relying only on historical data fail to account effectively for the effect of holidays, special events, promotions, prices and possibly the weather; these factors also distort the history and, unless removed before forecasting, warp the pattern of the series. In the same study, an exponential smoothing model taking promotion and special-event information as variables was 6 per cent more accurate than the same model without them, and an ARIMA model with variables was 13 per cent more accurate than the ARIMA model without.
In Turkey the most misleading part of the calendar is the religious holidays, because their dates change every year. According to the religious days calendar of the Presidency of Religious Affairs (Diyanet), Ramazan Bayramı (Eid al-Fitr) began on 30 March in 2025 and on 20 March in 2026, and will begin on 9 March in 2027; Kurban Bayramı (Eid al-Adha) began on 6 June in 2025 and on 27 May in 2026, and will begin on 16 May in 2027. Because each holiday moves ten to eleven days earlier every year, the same week last year is not the same week this year. A model that looks at the calendar week takes the holiday effect for seasonality and places it in the wrong week; the variable the model needs is the day's distance from the holiday. The planning side of this is covered separately in the blog post on why the religious holiday calendar disrupts retail planning.
A promotion variable is more than a yes-or-no flag: the discount rate, whether the product is in the leaflet, end-of-aisle display and which day of the promotion it is are separate variables. If the sales the promoted product takes from sister products and the dip after the promotion ends are not in the model, the promotion week is forecast well and the following two weeks badly. For paydays, M5 offers a good parallel: the dataset included the days on which purchases with US food assistance cards were allowed as a separate variable. In Turkey the same role is played by salary and pension payment days, and their effect is measured separately in the chain's own data, by branch customer profile.
| Variable | Example | How it enters the model | Watch out for |
|---|---|---|---|
| Promotion | Weekly deal discount, leaflet, end-of-aisle display | Discount rate, leaflet flag, day of the promotion | Effect on sister products and the post-promotion dip |
| Price | Shelf price change, pack size change | Price, ratio to previous price, unit price | Under inflation, relative price rather than absolute price |
| Religious holiday | Ramazan and Kurban Bayramı, holiday eve | Days to the holiday, eve flag, day of the holiday | Moves ten to eleven days earlier every year |
| Public holidays and school calendar | New Year, mid-term break, bridge days | Holiday and bridge-day flags | In branches in holiday areas the effect may run the other way |
| Salary and pension days | Payment day and the few days after | Days to payment | Effect varies with branch customer profile |
| Weather | Temperature, rainfall | Forecast temperature, hot-day flag | Measured separately for temperature-sensitive products (water, ice cream, watermelon); the weather forecast has its own error |
| Stock status | Stockout day, hour the shelf ran empty | Stockout-day flag, partial-day share | If not flagged, the model learns demand too low |
| Branch event | Refurbishment, a new supermarket opening nearby | Event flag and date | A past event is not carried into the future |
A variable can only go into the model if it is known at the time of forecasting. Next week's promotions and the holiday calendar are known; next week's weather is only known as a forecast. A model trained and tested on actual past weather will run on forecast weather in production, so it looks better on paper than it is.
Where does AI make the most difference: the lesson from the M5 competition
The study that best shows the place of machine learning in retail forecasting is the M5 competition, held in 2020 with its results published in the International Journal of Forecasting in 2022. The task was to forecast 28 days ahead 42,840 hierarchically linked series derived from the daily sales of 3,049 products sold in 10 stores across three US states. The dataset also included price, promotion and special-event variables; 5,507 teams took part.
The result cuts both ways. On one hand, the winning method was 22.4 per cent more accurate on the competition's overall accuracy measure than the best statistical benchmark (exponential smoothing aggregated bottom-up), and all of the top five methods improved on it by more than 20 per cent. According to the organisers, M5 was the first competition in which all the top-performing methods were pure machine learning methods and significantly better than all statistical benchmarks. Almost all of the top 50 methods used models that learn from the series together rather than one at a time; the organisers write that this also eases the problem of series with a short history.
On the other hand, the gain is not the same at every level. In the table below, at total level the winning method's error is less than half that of the benchmark; at product × store level the difference stays around 3 per cent. Only 7.5 per cent of the participating teams managed to beat the best benchmark. In other words, machine learning does not bring accuracy by itself: properly set up, it delivers a large improvement at total and middle levels and a limited one at the lowest level, where the dispatch decision is made. The uncertainty at the lowest level is still absorbed by safety stock, case pack and capacity rules.
The lesson for a grocery chain is this: machine learning makes the most difference where thousands of related product-branch series are driven by the same variables (promotions, price, holidays) and those variables are consistently recorded. If there are few series, the history is short or promotion records are scattered, a well set-up exponential smoothing model and a properly flagged calendar are often enough.
- Many related series: thousands of product-branch series are learned together, and a series with a short history benefits from its neighbours
- Frequent promotions and price changes: effects enter as variables and explain the series instead of distorting it
- A moving calendar: distance-to-holiday and holiday-eve variables work by the same rule every year
- Limited benefit: in intermittent product × branch series the gain is small; decision rules remain decisive
| Level | Winning method | Best benchmark | Improvement |
|---|---|---|---|
| Total (all stores, all products) | 0.199 | 0.426 | 53% |
| Store × department | 0.573 | 0.728 | 21% |
| Product × store | 0.884 | 0.915 | 3% |
| Average of the 12 levels | 0.520 | 0.671 | 22.4% |
How do stockout days hide demand, and what data is needed before starting?
Sales data shows not demand but the part of demand that was met. On a day the shelf runs empty, sales fall but demand has not; if the model learns that day as it is, it lowers the forecast, dispatch shrinks, the shelf empties earlier the next week and the error feeds itself. There is an effect in the opposite direction too. According to the global study released by GMA, FMI and CIES in 2002, of shoppers who meet an out-of-stock, 31 per cent go to another store, 26 per cent buy a different brand and 9 per cent buy nothing. So on a stockout day the missing product's demand looks low and the substitute's looks higher than it is.
To correct this, the stockout day must first be known. If the end-of-day stock balance is zero, or fell to zero during the day, that day is flagged; a flagged day is either removed from the training data or its demand is estimated and put in its place. In a machine learning model the stockout day is given as a separate variable; the best methods in M5 also used periods of zero sales as a separate piece of information. The basis of all this is an accurate stock balance: phantom stock that appears in the records but is not on the shelf makes a stockout day look like a normal day.
The data needed before starting is listed in the steps below. The common rule is that every item is stored at product × branch × day level and as it was known at the time of forecasting; a promotion calendar corrected after the fact cannot explain a past forecast error.
- Daily sales, product × branchAt least two years; two years give two instances of each religious holiday. Returns and voids separated from sales, and different barcodes of the same product brought together on one product record.
- Daily stock balanceEnd-of-day balance and, where possible, the time it fell to zero during the day. The stockout-day flag comes from here.
- Promotion calendarWith product, branch, start and end, discount rate, leaflet and display information; planned and actual kept separately.
- Price historyShelf price changes with dates; pack size changes flagged separately.
- Event calendarReligious holidays, public holidays, school holidays and bridge days; filled in for the past and entered at least a year ahead.
- Product and branch master dataProduct hierarchy, case and unit definitions, branch opening and closing dates, floor area and refurbishment periods.
Consistent records come before the model. No method can learn correctly from data in which the same product is sold under two barcodes, transfers are booked as sales or promotions are missing from the calendar; machine learning only repeats that error faster.
How is forecast accuracy measured: MAPE, WAPE and bias
The choice of accuracy measure decides which model looks good. MAPE, the mean absolute percentage error, is the average of each row's percentage error and the most common measure. Forecasting: Principles and Practice lists the weaknesses of percentage errors: they are undefined when the actual value is zero, become extreme for values close to zero and penalise over-forecasts more heavily than under-forecasts. In a grocery chain this means slow sellers run the whole table: a four-unit error on a spice selling four units a week counts as 100 per cent and hides the good forecast of bread selling 900 a week.
WAPE, the weighted absolute percentage error, adds up the absolute errors and divides by total sales; each product is weighted by its sales volume. Because dispatch and stock decisions are made in units, it is the more meaningful summary measure for a grocery chain. Bias measures the direction of the error: how far total forecast is above or below total sales. MAPE and WAPE show size, bias shows direction; a forecast with large but scattered errors is covered by safety stock, a forecast with small errors that always lean the same way is not. On this site positive bias means over-forecasting and negative bias under-forecasting; the forecast accuracy (MAPE) and forecast bias pages in the KPI library use the same definition.
Measurement follows three rules. First, the forecast valid when the order was placed is measured, not a later update. Second, it is measured at the level where the dispatch decision is made; at chain total, positive and negative errors cancel out. Third, the model is compared with the naive forecast: a model that cannot beat the same day last week adds no value. A forecast adjusted by a planner is measured the same way; if the adjusted forecast is not more accurate than the model's, the effort of adjusting is wasted.
- MAPE
Σ (|Actual − Forecast| ÷ Actual) ÷ n × 100- WAPE
Σ |Actual − Forecast| ÷ Σ Actual × 100- Bias
Σ (Forecast − Actual) ÷ Σ Actual × 100A positive value is an over-forecast, a negative value an under-forecast.
| Product | Actual | Forecast | Absolute error | Percentage error |
|---|---|---|---|---|
| Bread | 900 | 860 | 40 | 4.4% |
| Milk 1 L | 420 | 400 | 20 | 4.8% |
| Yoghurt 1 kg | 150 | 165 | 15 | 10.0% |
| Olive oil 1 L | 12 | 18 | 6 | 50.0% |
| Spice 50 g | 4 | 8 | 4 | 100.0% |
| Total | 1,486 | 1,451 | 85 | — |
Which forecasts does the planner review, and how does the forecast connect to dispatch?
An AI forecast does not replace the planner; it changes the job: instead of producing the figure, the planner reviews the exception. The review list is selected by rules, and each rule carries a reason. The table below shows typical exceptions and what the planner does in each; the thresholds are examples and are tuned on the chain's own data.
Reviewing has rules too. The study published in the International Journal of Forecasting in 2009, which examined more than 60,000 forecasts at four supply chain companies, found that large adjustments generally improved accuracy while small adjustments often damaged it; adjustments that pushed the forecast up were much less likely to improve accuracy than those that pushed it down, and were more often made in the wrong direction. Forecasting: Principles and Practice also recommends adjusting sparingly and only when there is important information the model does not have, with each adjustment documented together with its reason. In practice this means the planner, instead of saying 'let's add a bit', enters into the system the information that 'the school next to the branch opened in September'.
The forecast is not the final decision; the dispatch quantity is derived from the forecast through safety stock, stock on hand and in transit, case pack and shelf capacity rules. That step, how the forecast becomes a dispatch proposal and what AI does there, is covered in the guide on what AI does in store replenishment. In Mindpera the forecast enters Mind Send as the demand signal: recent sales velocity, similar-product history and branch cluster coefficients are read together; warehouse stock, branch shelf and backroom capacity and the minimum shipment pack are applied as constraints, and first allocation, replenishment and transfer proposals are generated automatically on every run. The demand forecast report shows forecast, actual and deviation together by product and branch.
| Exception | Signal (example threshold) | The planner's job |
|---|---|---|
| Systematic bias | Bias or tracking signal outside the control limit | Checks the data: stockout days, promotion flag, master data change |
| Upcoming promotion | A discount or leaflet in the next two weeks | Confirms the promotion information is complete |
| New product or new branch | Sales history shorter than four weeks | Checks the similar products and branch cluster relied on |
| Stockout day | End-of-day stock at zero in the last week | Checks the correction was made and there is no phantom stock |
| Sharp change | Forecast changed by more than 40 per cent on last week | Finds the cause; if there is none, leaves the forecast to the model |
Unless the planner's adjustment is stored in a field separate from the model's forecast, the value of adjusting cannot be measured. When the model forecast, the adjusted forecast and actual sales sit side by side, within a few months it becomes clear which kind of adjustment improves accuracy. In Mind Send the planner approves, rejects or edits the proposal line by line; every change is recorded with who made it, when and for what reason. Our team does the installation.
Frequently asked questions
- How does AI demand forecasting work?
- The model reads past sales at product × branch × day level together with variables such as promotions, price, holidays, weather and stockout days, and learns from thousands of series with a single model. Given the known values of these variables for the coming period, it produces a forecast for every product-branch pair. Its value is tested by comparison with the naive forecast and by measuring WAPE and bias.
- Is machine learning always better than classical forecasting methods?
- No. In the M5 competition the winning machine learning method was 22.4 per cent more accurate overall than the best statistical method, but at product × store level the difference stayed around 3 per cent, and only 7.5 per cent of participating teams beat the best statistical method. The benefit grows with many related series, frequent promotions and consistent records.
- What is the difference between WAPE and MAPE?
- MAPE is the average of each row's percentage error and gives every product equal weight; for slow sellers an error of a few units counts as 50-100 per cent and runs the average. WAPE divides the sum of absolute errors by total sales; each product is weighted by its sales volume. In the guide's five-product example MAPE comes out at 33.8 per cent and WAPE at 5.7 per cent.
- How much history is needed to start demand forecasting?
- At least two years of sales at product × branch × day level are recommended; two years give two instances of each religious holiday, and only then can the effect of the moving calendar be separated. Alongside sales you need daily stock balances, the promotion calendar, price history and an event calendar. Products and branches with a short history are started from similar products and the branch cluster.
- How do religious holidays enter the demand forecast?
- Not as a calendar date but as distance from the holiday: days before the holiday, the holiday eve and which day of the holiday it is are separate variables. Because religious holidays move ten to eleven days earlier every year, comparing with the same week last year misleads. The event calendar is filled in for the past and entered at least a year ahead.
- Should planners adjust the AI forecast?
- Only when there is important information the model does not have, and with the reason recorded. The study published in 2009, which examined more than 60,000 forecasts, found that large adjustments generally improved accuracy while small and upward adjustments often damaged it. If the model forecast and the adjusted forecast are stored separately, which adjustments work can be measured.
Sources
- Forecasting: Principles and Practice, 3rd edition (OTexts), section 5.2: Some simple forecasting methods — 2021
- Forecasting: Principles and Practice, 3rd edition (OTexts), section 5.8: Evaluating point forecast accuracy — 2021
- Forecasting: Principles and Practice, 3rd edition (OTexts), section 6.7: Judgmental adjustments — 2021
- Forecasting: Principles and Practice, 3rd edition (OTexts), section 8.1: Simple exponential smoothing — 2021
- Forecasting: Principles and Practice, 3rd edition (OTexts), chapter 11: Forecasting hierarchical and grouped time series — 2021
- International Journal of Forecasting, vol. 38, no. 4, pp. 1346-1364: M5 accuracy competition: Results, findings, and conclusions — 2022
- M5 Accuracy competition: Results, findings and conclusions, preprint (tables 1 and 3, section 3.6, findings 3 and 7, appendix B) — 2020-10-06
- International Journal of Forecasting, vol. 25, no. 1, pp. 3-23: Effective forecasting and judgmental adjustments: an empirical evaluation and strategies for improvement in supply-chain planning — 2009
- Food Marketing Institute, New Industry Study Explores Root Causes of Global Out-Of-Stock Dilemma (GMA, FMI and CIES study) — 2002-10-14
- Presidency of Religious Affairs (Diyanet), religious days calendar 2021-2028 (Turkish, accessed 15 October 2026) — 2026-10-15
- Presidency of Religious Affairs (Diyanet), list of religious days for 2027 (Turkish, accessed 15 October 2026) — 2026-10-15