Categories
Articles

Using atoti to leverage probabilistic time-series forecasts from a deep learning model

Ever wondered how can we leverage the outcome of a probabilistic time series forecast? How can atoti be used on top of the outcome from a neural network?

In this article, we will discuss how we can use atoti to leverage probabilistic time series forecasting from a deep learning model.

Here, we have used GluonTS, a solution from AWS, to do probabilistic time series forecasting for the sales number for a salad manufacturer. This probabilistic forecast is then used in order to optimize the inventory and find the optimum number of refrigerators to store the salad products.

If Tarot cards were right with probability =1, we would not have needed probabilistic forecasting at all!

What is probabilistic time series forecasting and why do we need it?

The concept of probabilistic forecasting was developed for addressing a very wide variety of issues such as commodity stock price forecasting or weather forecasting. The rationale behind a probabilistic approach or a quantile-based approach is quite simple: the less likely an event is to occur, it would be placed in the more extreme quantile. So the most likely prediction would be placed in the 50th quartile scenario.

The typical mean or median based methods tend to ignore the extreme situations and derive towards the “usual” scenario. Hence, in the domain of supply chain and food processing, these methods are not very effective at preventing both stock-outs and dead inventory. Quantile based forecasts approach can enable us to directly look at the scenario of interest, say avoiding stock-outs, and strive to provide a precise answer to this very problem of ignoring the extremes.

The probabilistic forecasting shows the entire spectrum of future scenarios

What exactly does GluonTS do?

GluonTS is a python toolkit for probabilistic time series modeling, built around Apache MXNet. It has been built by the Amazon Web Services — Labs. GlounTS leverages the truly open-source deep learning framework suited for flexible research prototyping and production at Apache MXNet.

GluonTS provides utilities for loading and iterating over time-series datasets. It provides classical models like ARIMA to forecast time series and also pre-trained state of the art Deep Learning models ready to be fine-tuned, and quickly experiment with different solutions. Also, it allows you to assemble pre-defined stacks in order to build your own Deep Learning architecture and train your model from scratch.

Most traditional time-series predictions predict a single ‘most-likely’ value for the future. Hence, in order to solve this issue, here GluonTS is used for making probabilistic forecasts and then the values corresponding to a mist of given quantiles are picked from the forecast.

With GluonTS you can also:

  • Train and evaluate any of the built-in models on your own data, and quickly come up with a solution for your time-series tasks.
  • Use the provided abstractions and building blocks to create custom time series models, and rapidly benchmark them against baseline algorithms.

Interpreting the results: The atoti magic!

In this use case, we have the composition, selling price, the volume occupied, and sales data for various salad products. And the objective is to optimize the storage for the future. The traditional approach would be to make a median-based time series forecasting for the sales and hence predict the storage capacity and the related cost.

But thanks to atoti and GlounTS, we can now make a prediction for various quantiles of the sales forecast and let the business choose how aggressive or reserved they want to be with the inventory acquisition and hence the manufacturing capabilities.

So once we get the quantile-based sale prediction outputs we put them in a vector and merge them to the existing sales store in atoti. This is then used to perform cube slicing and scenario creation for the additional storage capacity, associated cost incurred, etc.

Scenario creation

We create the scenarios for the sales prediction for the 0.99 and 0.01 quantiles. For the newly created scenarios, we calculate the available storage for three randomly chosen salad products.

Image for post

The availability of three salads products for various forecast quantiles.

Observation: Here we can see that for many salads, we need additional storage (i.e. the available storage is negative) only in the case of 0.99 quantile of sales. For some products such as the Caesar salad, we do not need the additional space even for the 0.99 quantile of sale.

How to interpret these volumes?

For the various prediction scenarios, since we have the number of products to be sold and given the storage capacity and the product volume, we can calculate the total additional volume required. This can be simply converted into the number of refrigerators with an underlying assumption that the storage capacity of a refrigerator is 200 Litres.

Additional refrigerators required

From refrigerators to additional potential margin:

Although these refrigerators can bring in some potential revenues, they also have an operational cost. So with how many refrigerators is the net margin maximum? Is it even profitable to acquire some additional refrigerators? Thanks to atoti, we can answer all these questions. Not only that, we can find the breakdown of the total costs and the total revenue for the scenarios with different numbers of refrigerators.

Here, we assume that the total daily operational cost of a refrigerator is 5 euros per day. And though there is no limit on the number of scenarios, for the sake of clarity we will compare the scenarios with 10, 15, 20, 25, and 40 refrigerators.

Q1 — How much of the total additional potential revenue can we actually realize in these scenarios.

The potential additional and the potential additional realized revenue against the number of refrigerators

Here we can see, as we keep on increasing the number of refrigerators, there is an increase in the additional potential revenue which can be realized. With 40 refrigerators, we can realize almost the full potential revenue.

Q2 — But how much would it cost to the business?

Total cost in various scenarios of refrigerators

Intuitively, the total cost keeps on increasing as the number of refrigerators increases. The production and ingredients cost increase proportionally to the number of products being sold on that day while the additional storage cost being constant depending on the number of refrigerators.

Here is a comparison of the total revenue and the total cost for the cases with a varying number of refrigerators.

Image for post
Comparison between the total cost and the total revenue for the various scenarios.

While having 40 additional refrigerators may materialize the full potential revenue, the return of investment ($3,730.90) is lesser than the rest of the scenarios. We can see that maximum revenue does not equate to the maximum margin in this case.

Q3 — So more potential revenue or less total cost, which scenario is the best?

We calculate the margin for the different scenarios and hence the one with the maximum positive margin will be our best scenario.

Margin can be defined as the difference between the potential additional revenue realized and the total cost for that scenario.

Image for post
The total margin with the various number of additional refrigerators.

Hence, it can be concluded that in the scenario with 0.99 quantile of sales, we get an optimum additional margin by acquiring 15 additional refrigerators. So we should not be acquiring more than 15 refrigerators at the given daily operating price and the capacity of the refrigerators.

Still Curious?

For the detailed source code and many other such interesting use cases, do check out the atoti notebook gallery on GitHub. And here is the article detailing the whole notebook and along with the data schema.