Technical

Three methods, one referee

We estimated the demand of stockout days three ways and tested each against the hidden truth. Which one won, where machine learning went wrong on the hits, where price elasticity sets a trap, and why the formula that is right in theory overstated.

Lost Sales · 3 / 5

The second of Pars’s three steps, measuring the rate on days with stock, is the easiest on paper. But on the shop floor nobody can know how well this step has been done. The customer who finds the rail empty is never written down anywhere; all you have is censored demandDemand that arrives while the shelf is empty and is never recorded. Sales data show not demand but the smaller of demand and stock.. What are you going to compare the estimate with?

At Lumoda there is a referee. Because the data is synthetic, we know for every store, every size and every day how many customers came, how many could not find what they wanted, and what those who could not find it did. The estimators never see this information. The referee is there only to mark the exam paper.

The rule is simple. Simple’s day multipliers and the machine learning model learn from Lumoda’s first two years. All three methods also read, in the exam year, the in-stock days around a stockout day, machine learning as features; none of them sees the referee. The exam is the third year. What the referee says for that year: unmet demand on the stockout days on which a loss can be written was 2,833,153 units.

Three methods

Naive. The average of the in-stock days in the cell’s last few weeks. It looks only backwards. It is the first reflex on the shop floor, and it is here as a baseline.

Simple. The in-stock days on either side of the stockout day. Each day’s sales are first turned into an ordinary day (day of the week, special day, price, the product’s age), then carried over to the stockout day’s conditions. What Pars wrote on the board in the previous article. It is called Simple because you can say in one sentence where every number comes from.

Machine learning. A single model that takes the same information and learns the relationships itself. It learns from every product and every store together.

The details of all three, settings included, are in the code in the site’s GitHub repository. This article looks at what they found.

The exam result

Bias is how far the total estimate strays from the referee’s total; plus means over, minus means under. WAPE is the sum of the absolute errors divided by the referee’s total. We measured at two levels: every product in every store, week by week, and the whole chain, week by week.

MethodTotal biasWAPE, store × product × weekWAPE, chain × week
Naive+45.8%79.5%51.1%
Simple+9.3%47.1%10.4%
Machine learning−14.7%58.0%16.7%

Simple leads on all three measures. Four things can be read from the table.

Naive goes wrong on a product that is slowing down. A backward-looking sum does not see the product slowing down. On Collection products Naive’s bias is +68.9%, on Outlet +113.1%. On NOS products, which sell steadily, it does not do badly: −5.1%.

“I always look at the last few weeks too,” says Ali.

“On NOS you’re right,” says Pars. “If a product sells at the same rate all year, looking back is enough. If it’s slowing down, it isn’t. That’s why I say look both ways.”

The error is large at cell level and small at chain level. Simple misses one product’s week in one store by 47.1%, and the whole chain’s week by 10.4%. The reason is how small demand is. A size’s daily demand in a store is usually one or two units; nobody can know whether four customers will come that day or none at all. Added up, the errors cancel each other out. Short stockouts are hard too: in gaps of at most three days, Simple’s WAPE is 79.2%.

Machine learning understates the hits. Among seasonal products, in the tenth that sold the largest share of what was bought, the hits, machine learning’s bias is −45.1%. We did not measure why; we have a guess: machine learning learns a single pattern for every product and may be pulling an extreme product such as a hit towards that pattern’s average. Simple looks at each cell’s own neighbouring days; it is thrown by the hits too, but in the other direction: +16.8%. Naive: +64.9%.

More complex is not better.

“So machine learning lost?” says Veli.

“In this exam it lost,” says Pars. “With more information and a better set-up the gap might close. But at the first attempt the method you can explain won. And it tells you where it made its mistakes, too.”

The elasticity trap

One of the day’s characters is price. A discounted day sells more. How much more? There are two places to measure it, and they give different answers.

The first is promotions. A promotion comes from outside: it is not granted according to how the product sold that week. Price elasticity measured from promotions: 1.75.

The second is markdown, the permanent in-season price cut. A markdown does not come from outside. Products that are not selling well get marked down. Sales after the markdown carry both the effect of the discount and the fact that the product was weak to begin with. Elasticity measured from markdowns: 1.28.

The gap looks small, but its consequence is not. At 30% off, sales rise to 1.87 times by the promotions’ measure, and to 1.58 times by the markdowns’. A model that learns its elasticity from markdowns underrates the power of a discount and understates the loss on discounted stockout days. Simple learns its elasticity from promotions. The figure learnt from markdowns stays in the report only for comparison.

The day that sells out: why the formula that is right in theory overstates

Picture a day that sells out. The rail opened in the morning with a few units and was empty by the evening. We know demand was at least as large as the stock. How do we write the loss?

The plain sum: take the stock away from the estimated demand, and do not go below zero. A crude sum; it does not use the information that demand exceeded the stock.

The sum that is right in theory: if we know demand exceeded the stock, we ask “given that demand exceeded the stock, by how much did it exceed it, on average?” Because it uses that information, it beats the plain sum on paper. At the start of the series we chose it as the main measure.

The referee counts the unmet demand on sold-out days as 251,386 units.

SumSimple’s estimateBias
Right in theory302,049+20.2%
Plain239,705−4.6%

The sum that is right in theory overstates. The same happens with all three methods: for Naive +19.3% against −4.2%, for machine learning +1.8% against −24.3%. That machine learning comes so close is most likely chance: its general understatement and the formula’s overstatement cancel each other out.

Why? The formula assumes two things: that the estimated demand is right, and that daily demand follows a particular random pattern. That it overstates tells us that on these days at least one of the assumptions does not hold. How much each one contributes we did not measure separately.

Pelin sees the table and asks straight away.

“The plain sum makes fewer mistakes, that’s obvious. Why don’t we switch to it?”

“Because we learnt that after seeing the referee,” says Pars. “Choosing the formula by looking at the referee is revising from the exam paper. On the shop floor there’s no referee. There you choose the formula from theory and common sense; and that’s how we chose it from the start.”

“But here we know which one is right.”

“Here we know. If we change the choice to fit the result, every number in this article is corrected with information nobody on the shop floor could use. We’re not changing the formula; we’re printing its bias as it is.”

Sold-out days are a small part of the total loss. Simple’s overall bias, with this overstatement included, is +9.3%.

What’s hard in your data

Every number in this article rests on a referee. In your data there is no referee. Put the three methods side by side and you will see three different numbers, and there will be no exam paper to tell you which is right.

There are things you can do. Holding back some in-stock days and estimating them again is the first that comes to mind. But a held-back in-stock day is not like a stockout day; it will not tell you how you go wrong on a stockout day. The real difficulty is deciding which method to trust without an exam paper. Our advice: choose the method whose errors you can explain. 🙂

By Sabri Suyunu