We keep hearing about artificial intelligence disrupting many industries. Here at Radiostudio, we have addressed a few use cases related to agriculture and kitchen inventory in the past. So why not take a step further and explore some related industry use case for AI in food and beverages. Let's take a dig at a typical fast-food chain and see how we can leverage artificial intelligence in the food industry.

More...

F&B industry is probably one of the most immature sectors when it comes to harnessing data. Mostly, due to the very nature of the business where the order placed by a customer sitting at the table takes paramount priority. However, there is one thing that generates enormous data, the PoS or billing machine.

Data extracted from the billing machine can usually tell us about the revenues generated, orders placed, and the items ordered, within a period. Let's assume that we manage to extract this data. Then the next obvious questions will be this.

Before we answer this question, please spare a few minutes to read this narrative below, about a person named Lorenzo.

**Here is this guy from Italy who runs a fast food restaurant serving pizzas. Meet Lorenzo. Lorenzo is obsessed with quality and customer centricity and hence wants to adopt an approach that can help him to source the best quality raw materials just in time so that he can continue to serve his customers without loss of loyalty or business.**

**Lorenzo sells some of the most sought-after flavors of pizzas. The most popular of them is the Margherita Pizza. It requires some exotic and authentic ingredients like the Mozzarella Bufala Cheese. Lorenzo wants to make sure that his raw material supply chain is functioning at an optimal level and he wishes to automate this system as per business demand.**

Predicting business demand is the number one wish for any business owner. In the F&B industry, this is imperative as the business owners have to deal with perishable raw material and unreliable supply regularly.

So, if we have the historical billing data then whats stopping us from predicting the future demand? By employing the techniques of machine learning, we can do so.

Read on to know how can we fulfill Lorenzo's desire to have a technology backed, automated supply chain.

Let's dissect the problem statement for Lorenzo.

We need to first simplify it as per specific objectives that directly impact his business.

To serve the customers without running out of the raw material stock during the business hours, 9 AM to 9 PM.

To stock up the perishable food/raw material for not more than one day, to preserve their freshness.

We also need to add in Loranzo's business constraints.

Keeping in mind the objectives, we can conclude that Lorenzo wants to make sure that he is always stocked up with fresh supplies so that he never disappoints his customers. In this case, we are talking about Mozzarella cheese which is the main ingredient and is a perishable item.

However, Lorenzo also needs to keep an eye of his supply constraints. In the midst of daily juggle between managing the kitchen and customer expectations, keeping an eye on the supply constraints puts a cognitive overload on Lorenzo's mind, and this can pretty soon become a burden for him.

What Lorenzo needs is an AI-driven system that keeps a tab on his inventory and can continually predict his supply requirements. Needless to say, the system should be intelligent such that it meets his objectives as well as constraints.

We can imagine a system comprising of weighing scales attached to a storage container that contains the raw materials. The system also digs out the historical sales data from the billing machine. These two data streams provide all the intelligence for Lorenzo to automate his supply ordering workflow.

In essence, we are streamlining the supply tracking and ordering workflow for restaurant owners like Lorenzo. Apart from that, we are also bringing in intelligence into the workflow for recommending optimum order quantity for the essential items.

We can define the use case steps for this system as follows.

- 1The system takes the weight on the inventory at the beginning of the day
- 2The system starts monitoring the depletion of weight
- 3The system predicts the threshold inventory level as per supply constraint
- 4Based on prediction, the system sends notification for placing an order within the supply constraint
- 5The system recommends the optimum order quantity to be supplied as per the quality objective

As the kitchen staff scoops out Mozzarella Cheese from storage container for every Margherita pizza, the system springs into action.

Looking for the tech that drives real-time tracking of kitchen storage containers?

Lorenzo can now peacefully focus on serving his customer without having to worry about

1. How long will the supply last? , and

2. How much quantity to order?

Let's look at a sample data-set that can make this work. Assuming that we can extract the number of pizzas sold each day for the last two years, we can frame it as a simple two column data-set, containing the date and the count of sale.

To demonstrate this use case, we have generated this dataset as a CSV file.

We also need the real-time data of stock consumption while the restaurant is serving the customers. Based on the supply constraints that we have examined earlier, there are three workflow scenarios.

- 1The stock will last almost till the end of the day - Can order after 5 PM
- 2The stock will not last till the end of the day - Need to order before 5 PM
- 3The stock will be surplus at the end of the day - There is no need to order today

Here is a snapshot of the consumption data (in weight, kgs) for all the three scenarios

**Scenario 1 - Order After 5PM**

**Scenario 2 - Order Before 5PM**

**Scenario 3 - Do Not Order**

As you can see, this is an hourly snapshot, which captures the weight of storage container from 11 am to 4 pm. The assumption is that every hour the system senses the weight of the Mozzarella cheese & predicts to check the possibility for one of the three scenarios. Since the supply ordering cut off time is 5 PM, the system has to decide before that time.

Just by looking at these graphs it may not be evident how to conclude on the ordering. In the next section, we will see how can we achieve this.

From the end user's point of view, the crux of the solution boils down to

- 1Sending Notification : Predicting whether the supply will last for the entire day, and notifying if it does not.
- 2Suggesting Recommendation : Finding the recommended order quantity for the supply such that it lasts a day.

Before we go any further, we need to perform yet another simplification of the problem.

The quality objective and supply constraints defined earlier are only applicable to perishable, high-value raw material. Since we are talking about Margarita pizza, Mozzarella cheese is the only thing that needs to go through this automated AI based workflow. Also, given the fact that the pizzas are sold in standard sizes, we can easily derive the order quantity of Mozzarella cheese if we know how many pizzas are going to be sold during a given day.

With this knowledge and considering the use case, we are ready to dive into the solution.

For notification, we need to figure out a way to measure the rate of depletion of Mozzarella cheese.

We can employ a simple linear regression model to predict the remaining quantity of Mozzarella cheese at 9 PM which is the closing time for the restaurant.

For this, we have to start tracking the consumption data as per the graphs shown above and keep plotting the linear regressing model of the left over quantity (in kgs) during the day. Based on the three possible outcome scenarios of the workflow, the regression lines might appear somewhat like this.

**Scenario 1 - Order After 5PM**

**Scenario 2 - Order Before 5PM**

**Scenario 3 - Do Not Order**

The red dot that you see is the prediction at 9 PM based on the regression line. This tells us how much of the Mozzarella cheese will be left at the restaurant closing time. Now it is easy to decide when to send the notification for placing orders.

For forecasting the order quantity, we have chosen the ARIMA model. Since our data-set is a form of time series data containing the dates and the pizza sales number, ARIMA model is a good fit for such data.

An ARIMA model predicts future values of a time series data by a linear combination of its past values, based on three parameters p, q, and d. Each of them represents one of the three components of the model, namely the AR (Auto-Regressive), I (Integrated) and MA (Moving Average).

ARIMA Forecasting - https://machinelearningmastery.com/arima-for-time-series-forecasting-with-python/

Wikipedia - https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average

ARIMA Modeling - http://www.statsmodels.org/dev/generated/statsmodels.tsa.arima_model.ARIMA.html

ARIMA Case Study - https://machinelearningmastery.com/time-series-forecast-case-study-python-monthly-armed-robberies-boston/

Step by Step Guide To Forecasting with ARIMA - http://ucanalytics.com/blogs/step-by-step-graphic-guide-to-forecasting-through-arima-modeling-in-r-manufacturing-case-study-example/

By combining the three parameters, the ARIMA model can be tuned to extrapolate future points of the time series.

In this case, we will use it to extrapolate the sales figure of Margarita pizza for the next day. So from that, we can easily derive the amount of Mozzarella cheese to be ordered.

If we run the entire sales data through the ARIMA model, here is how the forecast looks like.

This is the ARIMA generated sales forecast from the beginning. If you compare it with the actual historical sales data plotted earlier, you might notice that the predictions get better towards the end , where the historical time series data builds up.

It's time to do a quick demo. If you want to explore the technical solution, then head over to the GitHub repository.

Read the README file to setup, understand and run the demonstration code

Check out the source file that implement this use case and validate the results

Make use of the sample data files representing the scenario based weight data and historical sales data=set used in this demonstration

The code simulates the typical workflow as per the use case steps described earlier, except that the weight data of inventory is pre-populated through data files. Also, since we have three workflow scenarios, there are three variants of the weight data file. Here is the output that we get when we run the code for the three scenarios through an IPython console.

**Scenario 1 - Order After 5PM**

**Scenario 2 - Order Before 5 PM**

**Scenario 3 - Do Not Order**

The outcome of scenario 1 and 2 is the same. The only difference is the notification time, which varies based on the rate of stock depletion during the day. The recommended order quantity for Mozzarella Cheese is shown as 12.14 Kgs. This value is derived from the forecasted sale quantity of Margherita Pizza, assuming that one pizza takes in 50 Gms of Mozzarella Cheese.

That's the million dollar question.

There are proven ways to find the accuracy of the ARIMA model. By varying the three parameters of the model, namely the p (lag order), d (degree of differencing) and q (order of moving average), we can calculate the MSE (Mean Square Error) of the model. Combining this with the AIC (Akaike Information Criteria) value, which is a measure of the accuracy of the model, we can find out the best fit model.

By executing the model with all the permutations of p,d & q, it was observed that the lowest MSE was 30.23 for the ARIMA model (6,2,0) with AIC value 5456.69 and highest MSE was 43.86 for the ARIMA model (1,2,0) with AIC value 5774.75.

ARIMA Model with Maximum AIC Value

ARIMA Model with Minimum AIC Value

You can check out the README file to understand how to run the model test programs to generate the above metrics.

Indeed, this is quite a simplistic assumption. Unless it is tested through the iterative process of cross-validation, we cannot deploy it for a real-world application. We must also note that there are seasonal variations in restaurant sales which have to be addressed. ARIMA has one more variant called the seasonal ARIMA, which takes more parameters to induce the seasonal effects. So if we have to make this use case to the next level, then Seasonal ARIMA would be the logical choice.

Well, if you have followed this post this far then, you can undoubtedly frame up this problem as a generic inventory management use case. Most brick and mortar businesses have to maintain some inventory to run their businesses effectively. So this approach can help them automate their inventory ordering and monitoring workflows.

Let us know what you think about this idea. We would love to get some feedback from real businesses that might want to leverage AI and ML to manage their inventory chores to boost productivity and reduce wastage.

The technical demo & source code for this blog post are contributed by

**Aavritti Soni**, currently pursuing her bachelors degree in engg. from Vellore Institute of Technology, Tamil Nadu. Aavritti is an active learner and her interest lies in the area of Machine Learning, Natural language processing and Internet of Things.

**Annukriti Soni****, **currently pursuing her bachelors degree in engg. from of National Institute of Technology, Raipur. Apart from academics, Annukriti's interests lie in emerging technologies like Machine Learning, Artificial Intelligence and Big Data.

Shyam is the Creator-in-Chief at RadioStudio. He is a technology buff and is passionate about bringing forth emerging technologies to showcase their true potential to the world. Shyam guides the team at RadioStudio, a bunch of technoholiks, to imagine, conceptualize and build ideas around emerging trends in information and communication technologies.

Blockchain Smartphones: An Exploration of Several Market Offers

Blockchain Waste Management | One Man’s Rubbish is Another One’s Treasure

Intelligent Vertical Search with Watson Discovery

Realtime Customer Feedback Analysis with IBM Watson Natural Language Classifier

**Session expired**

Please log in again. The login page will open in a new window. After logging in you can close it and return to this page.