Marc Goessling
(Afresh patent-pending technology)
Grocery is a challenging and low-margin business. For a grocery store to be successful, it has to operate efficiently. One of the core differentiating operational factors is how well the store is able to manage perishable inventory. For perishables, there is a critical tradeoff between ordering too much and ordering too little. Over-ordering degrades freshness levels and causes food waste, which hurts the grocer’s bottom line profit and is bad for the planet. On the other hand, under-ordering can hurt top line sales if shelves drop below a desirable fullness level or, in the extreme case, if stores run fully out of stock for an item.
Afresh is a purpose-built fresh grocery platform that, among other products, offers an ordering solution for perishable inventory, powered by artificial intelligence (AI). We help grocers place optimal orders by serving order recommendations. In order to do so, our system has to be able to 1) accurately estimate the amount of fresh inventory in a store and 2) correctly forecast the future demand for each item at each store. In this article, we’ll focus on the latter.

Apart from seasonality and holidays, the most dominant factor that leads to dynamic changes in grocery sales is — you guessed it — the price! Grocers strategically use pricing to balance consumer demand and item-level profit margins to maximize overall profits. In particular, they can run advertised promotions to increase unit sales of particular items and incentivize new shoppers to come to the store. However, a price reduction also means a narrower profit margin for that particular item. Consequently, to run a profitable promotion, it’s especially important to be able to accurately predict how much increase in demand a promotion will cause such that customer demand for the promoted item can be met, while not over-ordering and risking costly food waste.
In this article, we explain why accurately predicting grocery demand during promotions is hard and how Afresh tackles this challenge with our proprietary forecasting solution.
Grocery promotions
Let’s start with some background on how promotions are implemented in a grocery store. At a high level, a promotion can be thought of as a combination of a price reduction and some level of increased visibility of the promoted item.
On one side of the spectrum, there are unadvertised price discounts, typically referred to as a “manager’s special”, that are often used by grocery stores to reduce overstock before it goes bad. But they can also be used as a loyalty reward for regular customers, as the discount is only known to shoppers who are already in the store.

In order to support the promotion, stores can employ a range of approaches to increase the visibility of discounted items. One simple way is by using in-store signage to highlight the special pricing. A more powerful way is to build a secondary “ad display” at a different location within the store, in addition to the primary display of the item, to drive greater visibility and interest.
Finally, one of the most effective means of driving additional foot traffic to the stores is by advertising through flyers (digital or paper) that announce upcoming weekly promotions to customers. These “weekly ads” are usually coordinated at the corporate level and planned well in advance. For many stores, they are of central strategic importance and a major sales driver.
Price elasticities in grocery
In this section, we dig more into how the different promotion characteristics make it challenging to accurately forecast demand during promotions. All else being equal, we know that demand is a monotonically decreasing function of price — people buy more when prices are lower and vice versa. To keep promo shelves full (and sales high) while avoiding food waste, the million dollar question we have to answer is how much does customer demand change when a given item’s price is reduced?
For historic promotions, we can quantify price-induced sales lift by looking at the ratio of actual demand during the promotion compared to expected demand if there had been no promotion. For the exploratory analysis here, we set the base demand to the same weekday sales in the week prior to the start of the promotion.
The task then becomes to understand how this demand ratio relates to the price discount. A classical approach is to model the demand ratio as some power e > 0 of the price ratio. This leads to the formula:
The quantity e is called price elasticity and its value in this model controls how strongly demand changes as a result of a price change. For example, if e = 1 then a 50% price reduction would be expected to lead to doubling of the demand.
While the elasticity model is simple and appears attractive, it doesn’t tell us how price elasticities can actually be estimated from data. And as it turns out, price elasticities are extremely variable and dependent on which item is being promoted, which store is running the promotion, and how they choose to run it.
In fact, if all we knew was the percentage discount, there would remain a large degree of uncertainty about the promotion effect. This is illustrated in the following plot, which shows the range of possible sales lifts for different buckets of price discounts.

An obvious reason why promotions have different price elasticities is that price discounts are offered for different items. We, at Afresh, have empirically found that premium, seasonal, or storable items tend to have a higher price elasticity (meaning sales lift relative to the price discount is larger compared to other items). Examples are berries, kiwis, mangos, melons, apples, potatoes, freezable meat or seafood. On the other hand, basic food items tend to have a lower price elasticity. Examples are bananas, bell peppers, cucumbers, fresh herbs, lemons, onions or tomatoes. This makes intuitive sense from the shoppers’ perspective as price-conscious shoppers may look for the greatest savings in dollars and items that are more storable are more attractive to stock up on when a discounted price comes around.
Beyond elasticity variations across items, promotion effectiveness can also vary substantially by store. This is illustrated in the plot below, which shows sales for the same item at different stores. Sales lift is greatly different, even though the price discount is identical. A partial explanation for this is that shopper audiences at different store locations may have different levels of price sensitivity.

More critically though, stores may choose to “implement” the promotion differently in terms of visibility changes to the promoted item, as described in the previous section. The same price discount will have varying impact on consumer demand if it is unadvertised versus highlighted via secondary display versus placed in a store’s weekly ads.
Due to these various factors that influence the impact of a price change on customer demand, explicit modeling of each price elasticity for every item and every store would be very tedious and likely impossible to get entirely right. In particular, a given upcoming promotion of the form (item, percentage discount, visibility change) may have never occurred before in this exact combination. Consequently, we have to be able to generalize from previous similar promotions. The appropriate paradigm to solve this challenge is to learn from historic data using modern AI tools. This is indeed the approach our solution follows, as we describe in the next section.
Promotion-aware forecasting using deep learning
In this section, we describe the solution developed at Afresh to accurately forecast grocery demand, including during harder-to-predict promotions. Efficient inventory replenishment, in some form or another, comes down to determining the appropriate target inventory level such that future demand D can be met with a high probability q ∈ (0, 1), also known as “service level”. Formally, we are seeking “probabilistic forecasts” f with the property that

i.e. the probability that actual demand is less than or equal to forecasted demand is q. Such forecasts are also known as “quantile forecasts” for quantile q.
Quantile forecasts can be obtained by running a “quantile regression” over historic demand data d. This means we are constructing a mapping from input features to forecasts f such that the following weighted forecasting error is minimized (the first part is the under-forecasting error and the second part is the over-forecasting error). The technical term for this quantity is “quantile loss”.

Many modern forecasting systems today use “Deep Learning”, which means that the neural network family of AI models is used to construct the input to forecast mapping. While Deep Learning models have become widespread in recent years, they are still nascent in the grocery domain. With Afresh this is changing though! By working closely with our customers, we have built a Deep Learning solution specifically for grocery demand forecasting. The neural network architecture we are using is depicted below.

We first explain the high-level intuition behind neural networks before discussing the input features we’re using. The model architecture we deploy is known as an encoder-decoder network. The intuition behind this architecture is that raw inputs are transformed through the encoder into an “abstract representation”. This signal is then passed through the decoder to produce the desired forecasts. Encoders are sequences of learned transformations that extract the most relevant information from the inputs. They are inspired by processing in biological neural networks. The extracted signal coming out of the encoder can be thought of as the most compact summary of the input data in terms of relevancy for predicting future outcomes. The decoder’s job is to produce the final output, which, in our case, are forecasts of future customer demand for individual items at individual grocery stores. A decoder is again a sequence of learned transformations that starts from the encoded input and incorporates additional information about the target horizon (i.e. the time range we’re forecasting for).
Let’s now turn to the input features in our model. Unsurprisingly, one of the primary signals we use are historic sales of the item we’re forecasting for. Additionally, we pass the day of the week we’re forecasting for to the decoder, together with indicators about upcoming holidays that are relevant to consumer demand in grocery. In order to deal with price changes, we use past prices in the encoder and future prices in the decoder.
As discussed in the previous section, price elasticities depend on the item and on the store. In order to account for these effects, we trained “categorical embeddings” for item IDs and store IDs. Embeddings are transformations that identify similarities between different IDs so that learnings from the training data can be efficiently shared across appropriate subsets of items or stores.
Promotion-related visibility changes are harder to track. To account for them, Afresh uses an item’s display size setting, expressed as the number of units the corresponding floor display(s) can hold. We use past floor capacities in the encoder and forward-looking floor capacities in the decoder. This allows our model to adjust forecasts accordingly when displays are enlarged for the promo or when secondary ad displays are set up.
Last but not least, grocers may use more complex forms of discounts beyond price reductions for single units of individual items. For example, “Buy X Get 1 Free”, “X for $Y” (e.g. “10 for $10”), or “Mix & Match” (which allow the shopper to combine multiple different items to get a discount). There can also be different pricing tiers based on membership status with the grocer. In order to deal with these more complex types of promotions, Afresh developed a taxonomy to map our customers’ pricing information into a standardized set of promotion types and associated price discounts. Past and future promotion types are the final input features used in our forecaster.
Quantitative results
In this section, we study how Afresh’s forecasting solution performs over the course of a week-long promotion. Performance is evaluated in terms of two metrics: quantile loss and calibration. Quantile loss is the weighted error objective the forecaster is optimized for (see previous section for more details). Since demand forecasts are a primary input to our order recommendations, forecasting errors directly impact ordering accuracy. While lower quantile loss is better, it’s difficult to know how far away from optimal a given forecast is. The theoretically optimal quantile loss is 0 but this would correspond to every single forecast being perfect, which is of course unachievable. To get around this difficulty, a useful diagnostics metric is calibration, which refers to the percentage of items that had actual sales less than or equal to the forecasted value. For quantile forecasts, the optimal calibration is equal to the nominal quantile q. Below, we specifically study P80 forecasts, which is another name for quantile forecasts for q = 0.8 (see previous section for more details). Such forecasts are optimally calibrated if the forecasted value is above actuals 80% of the time.
In our analysis, we use 3-day forecasting horizons, i.e. the target quantity we are predicting is combined demand for the next 3 days. This choice makes sense because consecutive order days for many grocery items are 2 days apart with a lead time (duration between ordering and delivery) of 1 day. In order to contextualize the performance of our promotion-aware forecaster, we first look at what a grocer would experience if a promotion-unaware demand forecaster was used. This can be simulated by removing the promo features (price, promo type, display size) from our architecture and refitting the neural network. As it turns out, such a forecaster would see a 2–3x increase in quantile loss during promotions compared to forecasting errors off promo. Calibration of the promotion-unaware forecasts drops to about 50% at the beginning of promotions. In practice, this means that there would be a substantially elevated risk that promoted items run out-of-stock or drop to low fullness levels early during the promotion. Conversely, when the promotion ends, promotion-unaware forecasts are over-calibrated. This means that food waste risk would be increased after the promotion because unit sales do not reach the forecasted level.
We now turn to Afresh’s promotion-aware solution and provide a detailed discussion of its accuracy. The plot below shows how quantile loss evolves throughout a promotion when Afresh’s forecasts are used. The x-axis refers to the first day of the target horizon. Negative values correspond to days before the promotion. The promotion starts on day 1 and runs until day 7. Values 8 and larger correspond to days after the promotion. The y-axis is normalized to equal 100 on day -2. The high-level takeaway from the plot is that while forecast accuracy is not constant throughout the promotion, normalized quantile loss never gets higher than 130, which is substantially better than with a promotion-unaware forecaster (where normalized quantile loss gets as high as about 300 during promotions).

Let’s discuss the shape of the accuracy curve in more detail. Initially, we see a small uptick in forecasting error between 15% and 30% on days -1, 0 and 1. This is not surprising given that -1 is the first day for which the 3-day target horizon overlaps with the promotion period (which starts on day 1). The reason why quantile loss increases at all is that promo-related sales lift is not perfectly predictable. Consequently, even with an effective forecaster, there will always be some amount of additional uncertainty at the start of a promotion compared to times off promo (day ≤ -2 or day ≥ 9). Note that calibration in our forecaster is 77.5% on day 0, which is nearly optimal (the nominal value is 80%).
On day 2, i.e. 1 day after promo start, quantile loss drops by about 25% compared to the previous day. This can be explained by the fact that, by that time, the forecaster has knowledge of how sales played out on the first day on promo (day 1). In other words, sales data from the promo start day are a highly informative signal. Practical implications of the promo accuracy curve are that grocers need a slightly elevated amount of safety stock heading into the promotion — just to be able to cover the long tail of successful promotions. But as soon as the first day of the promotion is over, required safety stock levels return to normal levels and even below (in relative terms).
In the middle of the promo week (days 3–5), quantile loss is actually lower than it was before the promotion. This is likely because sales volume is higher during promotions (on aggregate about 2–3x), which leads to a higher signal-to-noise ratio and hence an easier forecasting problem compared to times with fewer sales. On the first day after the promotion (day 8), there’s another small uptick in quantile loss on the order of 15%. Our reasoning for that behavior is that demand after promotions does not always immediately return back to pre-promo levels (can be higher or lower), which causes some small degree of excess uncertainty.
Conclusion
In this article, we have explained the underlying factors that drive the outcomes of grocery promotions. We presented the Deep Learning solution we have implemented at Afresh to produce accurate forecasts for demand during promotions.
This is particularly important to our grocery customers because, in recent years, the macro-economic environment with high inflation has led to increased price awareness among shoppers. This makes competitive pricing more important than ever. At the same time, reducing the price for a given item reduces its profit margin, so it becomes all the more critical for stores to order the right quantity of that item to effectively increase unit sales without incurring costs from food spoilage.
Being able to successfully manage perishable inventory during promotions is a big challenge. Afresh helps grocers master this challenge by providing accurate order recommendations using modern machine learning tools tailored to the fresh grocery domain, including the ability to quickly adapt to a wide range of promotion techniques across variable items and stores.
Marc Goessling is a Staff Applied Scientist at Afresh. Our teams conduct research on demand forecasting, inventory estimation, inventory count targeting, order recommendations, display rightsizing, and food waste measurement.
If you’re interested in joining Afresh, take a look at our current job openings.
