Accounting for Censored Demand in Sales Forecasting

Sawyer Birnbaum, Machine Learning Product Manager

Afresh Engineering
Apr 14 · 4 min read

At Afresh, our mission is to reduce food waste and make fresh food more accessible by transforming the fresh food supply chain with technology. Every year, one-third of food produced goes to waste, globally. In the United States, 40 percent of all food waste occurs at the retail and consumer level, with the highest occurrence in fresh food departments. We build solutions for better store-level forecasting, ordering, and operations for fresh food, so they can boost profits and bring fresher food to their communities.

At the heart of every food waste minimizing order is an accurate forecast of future demand. To produce such a forecast, we rely heavily on past sales, which under most circumstances offer a window into past demand. The factors contributing to the demand for an item may be complex — a conglomeration of traits such as price, weather, seasonal trends, and the idiosyncrasies of a store’s customer base — but ultimately, past sales demonstrate how these factors come together to impact demand, and they therefore serve as a basis for our demand model.

In some cases, however, sales do not reflect demand. This occurs when inventory of an item runs out or falls to a visually unappealing level that discourages purchases. On a day when a store has only 50 apples in inventory, it cannot sell more than 50 apples, regardless of the demand. The divergence between the sales of an item and the demand for that item is known as “demand censoring” (because the available inventory “censors” the observed demand), and it can seriously undermine recommendation accuracy.

When training a demand forecasting model, demand censoring reduces the quality of the training data and therefore the quality of the model. For example, if a large promotion in the training data resulted in a stockout, the model may fail to fully appreciate the impact of the promotion, which could result in under-forecasting if the promotion happens again. Additionally, demand censoring can magnify the cost of under-predicting. If demand censoring occurs when the model recommends too little, not only will there be an immediate cost to the store due to the under-prediction, but — because we use past sales as a feature in our model — the lower sales will push the model towards lowering its demand forecast, potentially exacerbating the under-prediction problem. In the worst case, a model that does not account for demand censoring can become trapped in a “death spiral” in which lower demand forecasts result in lower inventory which in turn leads to lower sales and therefore even lower demand forecasts.

To avoid the problem of censored demand, we use a two-step process: (1) we identify days with censored demand, and (2) we impute the true demand on those days. If we have inventory data on a frequent basis, we can flag days when inventory dropped to zero as days with likely demand censoring. When frequent inventory counts are not available, we look for patterns in the shipments and sales data that indicate possible censoring. (This often applies to the period before the launch of the Afresh product, as grocery chains’ records normally provide only a snapshot of inventory every few weeks.) For example, if sales briefly drop to near zero for a normally high-volume item, then the item likely went out of stock. Once we identify a set of days with imputed demand, we adjust the sales on those days to reflect our estimate of the true, uncensored demand.

The below figures display the detection and imputation processes, using the demand censoring detection algorithm that does not rely on inventory. The first figure shows the sales pattern for a fictional produce item. Days with possible demand censoring are noted with blue lines. The second figure shows the sales patterns after imputing the demand on these days. After imputing the demand, some of the irregularities in the sales data have been eliminated, resulting in a more predictable (and hopefully more accurate) picture of the demand for this item.

Sales before adjusting for censored demand.
Sales after adjusting for censored demand

Accounting for censored demand is a challenging task and a vital one for providing good recommendations. As the above figures show, our system allows us to identify days with censored demand and recover an estimate of the latent demand. And we are experimenting with techniques to improve our ability to detect demand censoring and to more accurately impute the demand on these days, such as better accounting for the sales of substitute items. We look forward to sharing our results!

We are growing our team rapidly and are looking for passionate, talented engineers to help us solve more problems like this. If you are interested in joining, take a look at our current openings.

Afresh Engineering

Afresh Engineering

Afresh is on a mission to reduce food waste globally by transforming the fresh food supply chain. We build AI-powered solutions that meet fresh food’s many challenges to optimize grocery retail forecasting, ordering, and operations.

Afresh Engineering

Written by

A fast-growing team that’s passionate about how technology can reduce food waste and make fresh food available to all. Learn more at

Afresh Engineering

Afresh is on a mission to reduce food waste globally by transforming the fresh food supply chain. We build AI-powered solutions that meet fresh food’s many challenges to optimize grocery retail forecasting, ordering, and operations.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store