1. Courses
  2. Data
  3. Data Science and Machine Learning
  4. Stop 4

35 minIntermediate

Forecasting demand

A demand forecast is useful only when it turns into a good order. This lesson shows you what grocery demand is made of, how to teach a model about festivals that move every year, which error measure to trust, and how to forecast a percentile instead of a single number so the order balances empty shelves against waste.

By the end you can

  • Break a demand series into level, trend, weekly and yearly seasonality, and events such as festivals, salary days and promotions
  • Build festival features that follow a moving festival, and compare with last year by festival date
  • Choose between one global model and one model per series, and know what to do with slow movers
  • Pick an error measure (MAE, RMSE, MAPE, WAPE, bias, MASE) that fits the decision, and report it per store, product group and horizon
  • Forecast a quantile, turn it into an order quantity, and set a lower percentile for perishables

The everyday picture

Think of a tea stall at a busy bus stop. Every morning the owner buys milk for the day. She does not buy the same amount every day. She knows Fridays are busy, that the last days of the month are busy because people have just been paid, that rainy evenings sell more tea, and that the festival eve is the busiest day of the year while the day after is quiet.

She also does not buy exactly the number of cups she expects to sell. If she runs out at 5 pm, she loses the evening crowd and some of them start buying from the stall across the road. If she buys too much, the extra milk turns sour by tomorrow. So she buys a little more than her best guess on normal days, and less extra on hot days when milk spoils faster. That is the whole lesson: know the shape of demand, mark the special days, measure how wrong you usually are, and order at a level that matches the cost of each kind of mistake.

What demand is made of

In Framing a problem as a model you set the target: units of one product, in one store, for each of the next 1 to 4 days, predicted tonight. Before you model it, look at what a demand series is made of. Forecasters split it into parts, because each part needs a different kind of feature.

  • : how much the product sells on an ordinary day in this store. Milk in a large store might sell about 200 litres a day; the same milk in a small store, 40.
  • : a slow change in the level. A new housing block near a store, or a brand that is losing customers to a cheaper one.
  • : patterns that repeat. Weekly: weekends sell about 30% more than weekdays in many Mangrove stores (approximate). Monthly: the days around month-end salary payments. Yearly: school term, hot season, monsoon.
  • Events: one-off or moving days. Festivals, promotions, a cricket final, a heavy rain evening, a power cut. They are rare, so a model sees each one only a few times, and they are where most of the forecast error comes from.

Events also change the days around them. Before a festival, families buy rice, oil, sugar and sweets several days early, so demand is : it climbs for about four days, peaks on the eve, and then drops below normal for a few days while people eat what they bought. Promotions do the same on a smaller scale. A 20% discount on cooking oil lifts its sales in the promo week, then sales dip the week after because people stocked up. Some of the lift is also taken from other brands of oil, which is called .

Now look at today's ordering rule from that angle. The 28-day average treats every one of the last 28 days the same. It cannot see the weekend coming, it cannot see a festival coming, and when the festival arrives it only slowly notices. One spike day adds about one twenty-eighth of its size to the average, so the average stays low during the festival and then stays a little high for four weeks after it, exactly when people are buying less. The diagram shows this for one product.

Units a day, 6 weeks 0 100 200 actual demand 28-day average weekends festival pulled forward dip after under- forecast week 1 week 5 week 6
The real series has a weekly ripple, a climb before the festival, a spike on the eve and a dip after. The 28-day average is flat through all of it: far too low on the festival days, then a little too high for weeks afterwards.

Quick check

A product sells about 95 units on weekdays and 130 at weekends. A festival is 10 days away. What will the 28-day average forecast do over the next three weeks?

Loading the rest of the lesson…