Advanced Analytics

Detection of product availability breaks on shelves

The challenge

One of the great challenges experienced by supermarket chains is to achieve the timely replenishment of products in the stores, so that they are available when the customer goes to look for them in the gondola.

As Brain Food, we participated in a project with a supermarket chain to improve the availability of products in stores and avoid the loss of sales due to lack of them.

The project had a series of tools and fronts to work on in order to achieve the objective:

  • Mathematical and computational model for predicting demand for the different products in each of the chain’s stores.
  • Live alerts that would warn the operation of products with availability problems.
  • KPIs and reports associated with the model’s predictions and results.
  • Application that will connect to the systems and communicate the results to the operation.

We want this app to quickly become widespread in our operation, as it helps enormously in the daily management of premises and internal organization.

The strategy


Based on the sales history of the supermarkets, train an XGBoost type model that made a demand prediction for each product, store, day and time. Given the magnitude of the problem, it was a complex solution to implement, in which it was necessary to combine many variables: discounts, holidays, quarantine, etc. In addition, products were clustered according to sales distribution categories.


The challenge was to implement in a few weeks a tool that would alert the operation which products to restock, since they were not having the expected sales. In conjunction with the client, we studied that it was reasonable to model the sales of the products using a Poisson distribution, under this assumption it can be assumed that the times between events are exponentially distributed with parameter corresponding to 1/lambda, where lambda corresponds to the average sales per hour of each of the products. This allows to determine the probability that each product will spend a certain time without selling and, when it exceeded a critical margin, it was added to the alert and announced to the operation.

With this simple tool implemented in just a few weeks, we obtained results of more than 50% accuracy in the alert, i.e., at least one out of every two products announced live was indeed having availability problems. The client, in its initial calculations to estimate the availability of products, was obtaining an accuracy between 10% and 30%, so the result of our tool meant a significant improvement in this aspect. It is also important to highlight that these results were obtained even under the effect of external variables that had a great negative impact on the prediction, such as quarantines and phase changes due to covid. This allowed the operation to solve the problem live and go to replenish the indicated product, thus avoiding loss of sales.


The indicator of how much sales had been lost due to unavailability was a combination of the two components already described: model and alert. First, it identified with the same Poisson probability logic which products were actually having a sales break. And, secondly, for these, it determined the amount that should have been sold according to what the model indicated. This determined how much sales had been lost. The KPI made it possible to identify the amounts of lost sales that were being made by each of the supermarkets, to compare, to see trends and to take action on them.


An important challenge of the project, and transversal to the components mentioned above, was the communication with the operation. For this, we programmed an API that connected to the servers that contained the results of the model, KPIs and alerts and this, in turn, delivered the data to an application that displayed the information on the operation’s cell phone.


of demand prediction


of stock breakage


on losses associated with stockouts


to have real time information

The achievements

At the end of the project, as a team we are aware that there are several improvements that could be made to the solution, such as relaxing the assumption that the distribution of products is Poisson and studying in detail other possible variables that could affect the results of the model, such as products that are substitutes for each other.

As a final product we obtained a program that was able to connect to the client’s systems, search for historical sales, predict the demand that had not been made due to availability problems, discriminate by probability of breakage, make an alert and build a KPI automatically. All this in a continuous flow of information that did not end up in the servers where the model was programmed, but in the cell phones of the operation and in Power BI reports that each management reviewed.