How to use the Machine Learning Solution Template for predicting demand forecasting in retail?

This article demonstrates how to use the Demand Forecasting Machine Learning Solution Template for a retail business.

 

Typical demand forecasting applications require extensive manual processes from their demand planners. It continuously requires careful data cleaning, feature extraction/creation, model training, performance analysis and prediction. These tasks vary depending on the business and require extensive expert knowledge for proper set up.

The AI & Analytics Engine offers an effective solution to this problem with the Demand forecasting ML Solution Template. You just need to enter some information about your business nature and requirements, and the entire process will be automated, enabling you to forecast demand efficiently and accurately.

This article will explore the Demand Forecasting template for a retail business.

🎓 To learn more about other templates in the AI & Analytics Engine, read What templates are supported on the Engine

Use case

Let’s say you are a demand planner of a large supermarket chain that has branches over multiple cities and states. You need to forecast the demand for products sold in the supermarkets in time so that you can arrange for the timely delivery of the products from sources to the shops.

Specifically, your team requires the daily demand of the products for a month at a time. Demand has to be forecasted monthly on 1st day of the month before. For example, the daily demand from June 1st to June has to be forecasted on May 1st. Not only you need to forecast demand for individual products on each store, but also you need aggregated demand for each product family in each city and state. You also want to look at prediction intervals too to prepare for the forecast uncertainty.

To achieve this, you use the Engine's demand forecasting template for retail businesses to build a machine learning powered app that forecasts the demand for the products accurately.

Data

Following datasets from a retail supermarket chain will be used in this article to demonstrate this.

Sales history dataset

This dataset contains the daily sales (unit_sales column) for multiple items (item_nbr column) in multiple stores (store_nbr column) for approximately 2 years. Also contains an onpromotion column that indicates whether the item was on promotion or not.

Preview of Sales_history datasetPreview of Sales_history dataset

Product info dataset

This dataset contains additional information about products (item_nbr column) such as family and class the product belong to and also whether item is perishable or not.

Preview of Product_info datasetPreview of Product_info dataset

Location info dataset

This dataset contains additional information about stores (store_nbr column) such as the city and the state the store located, the type of store and the cluster the store belong to. A cluster is a grouping of similar stores.

Preview of Location_info datasetPreview of Location_info dataset

Holiday events dataset

This includes holidays in cities where supermarkets located. The column city can be mapped to city in Location_info dataset.

Preview of Holiday_events datasetPreview of Holiday_events dataset

 

💡This supermarket sales data are obtained and modified from the Corporación Favorita Grocery Sales Forecasting, which is publicly available.

Creating a Demand Forecasting App

In this section, you can follow some simple steps to provide the required data and information to create an application that uses machine-learning models to forecast demand for a retail business.

To access the app builder, on the Project Home page, select Demand Forecasting under Machine Learning Solution Templates.

Select Demand Forecasting template from project home pageSelect Demand Forecasting template from project home page

Then create the application by selecting the Use this template and naming the application. This will take you to the App builder pipeline.

Select Use this template to create the applicationSelect Use this template to create the application

Step 1: Select use case

Within the app builder pipeline select Retail Demand option.

Select Retail demand optionSelect the Retail demand option

Step 2: Define business requirements

Here, you need to define the business requirements of the application. This includes:

  • What do you want to forecast: Forecast granularity and forecast horizon size? Select daily sales for 1 month.

  • What is the starting date of your first forecast period? Select 2017-09-01 as sales history data contains until 2017-08-15.

  • When do you need this forecast? Select generate forecast 1 month ahead on the 1st of the month.

  • Whether you want to generate prediction intervals or not? Select Yes. Then you need to Specify the prediction interval levels you are interested in. Keep it as default levels which are 80% and 95%.

  • Whether you want to forecast separately for different SKUs, product categories etc.? Select Yes.

  • Whether you want to forecast separately for different locations (e.g., by store ID, region, etc.)? Select Yes.

🎓 To learn more about prediction intervals, read What are prediction intervals?

Fill the business requirements related to your demand forecasting problemFill the business requirements related to your demand forecasting problem

Step 3: Add data

Review the data requirements to build the models. Based on the parameters provided when defining the business requirements, the sales history data must span at least 3 months.

The data you need are:

  • Sales history data (required data)

  • Holiday data (optional data)

Review data requirements-1Review data requirements

Then check the data requirements for Sales history data and add the dataset. After adding the data you need to provide column information about this dataset. This includes providing the details such as:

  • Sales timestamp column

  • Sales quantity column

  • The most detailed product identification column

  • The most detailed location identification column

Review Sales history data requirements and add datasetReview Sales history data requirements and add dataset

Also, you'll need to provide some additional information about the dataset such as:

  • Does your sales dataset contain supporting product information for each 'item_nbr'? Select No as there is a separate product_info dataset for that.

  • Does your sales dataset contain supporting location information for each 'store_nbr'? Select No as there is a separate store_info dataset for that.

  • In your business, are there seasonal patterns in demand? If Yes, what are the demand patterns? Select Weekly, Monthly and Yearly options.

  • On the day the forecast is generated, do you have data about all sales up to that date? This is used when there is a delay in collecting data. For this guide select Yes.

Provide details about sales history datasetProvide details about sales history dataset

When you select No to the questions:

  • Does your sales dataset contain supporting product information for each item_nbr?
  • Does your sales dataset contain supporting location information for each store_nbr?” 

two new optional steps appear in the app builder to upload any supporting information on products and locations. Since you have two datasets with product info and store info, add those datasets here.

Review product Information data requirements and add dataset

Review product Information data requirements and add dataset

Provide details about the product Information dataset

Provide details about the product Information dataset

Review location Information data requirements and add dataset

Review location Information data requirements and add dataset

Provide details about the location Information dataset

Provide details about the location Information dataset

 

Then there is the window to add optional holiday data. You can add the Holiday_events dataset here. Then map the city column in this dataset to city column in Location_info dataset.

Review holiday data requirements and add dataset

Review holiday data requirements and add dataset

Provide details about the holiday dataset

Provide details about the holiday dataset

Step 4: Define granularity levels

Often, demand planners need demand forecasts for multiple levels such as demand for each product in each store, demand for each product in each city, demand for each product in all stores, etc. This step can be used to define such required granularity levels.

There are two types of granularity levels. For product granularity levels, select family as a higher level to “item_nbr” which is the lowest level. For location granularity levels select city and state as higher levels. Keep both All products and All locations ticked. This will ensure the grand total demand of all products and all stores will be calculated. In right side panel you can see all the combinations of specified subgroups the forecasts will be generated for.

Define granularity levelsDefine granularity levels

🎓 For more information on granularity levels, read What are hierarchical granularity levels?

Step 5: Configure training

There are two main configurations you can do.

  • If you know how far back into the past the data is still relevant for forecasting, then you can update it here. Otherwise the Engine will use a default value of 5 years. Use default in this guide by selecting No to the question.

  • Advanced configurations: Use the default configurations for this guide

🎓 For more information on changing advanced configurations, read How to change advanced configuration for model training?

Configure trainingConfigure training

Step 6: Review forecast & evaluation

Here you can review how forecasts are generated and how the forecasting models are evaluated. This is the last step of the App builder pipeline.

Review forecast & evaluationReview forecast & evaluation

Once you are satisfied that you provided and reviewed all necessary data and information, click Start building. The app-building process will start as soon as you complete this step, and the resulting app will allow us to explore the model insights and make predictions.

You will be directed to the App summary page with the label Processing. You can see the progress of the app in each panel.

App summary page when app is processingApp summary page when app is processing

Understanding the app summery page

Once the app is ready, the app label changes to Ready.

App summary page when app is readyApp summary page when app is ready

In the App summary page, there are a few tiles that show different steps of demand forecasting.

  1. App setup - Shows user inputs such as datasets and configurations

  2. Data preparation - Shows how data is prepared using a data preparation pipeline and prepared training data which is used for model training

  3. Model training - Shows the model training status

  4. Status and results - While the app is in processing this shows the progress of the app. Once the app is ready, this tile shows a summary of its performance and next steps.

Below these tiles are the forecasting results. Once model training is finished, you can see the forecast results for trained models for the last forecasting period.

Forecasting results for all products in all locationsForecasting results for all products in all locations from 1/09/2017 to 30/09/2017

Inspecting a forecasting model

In the last tile of the app summary page you can see the model with highest forecasting quality. You can click on the model here to inspect its performance.

🎓 To learn more about forecast quality in demand forecasting apps, read Demand Forecasting Forecast Quality

Best model shown in the app summary pageBest model shown in the App summary page

 

If you trained multiple models and wanted to know more insights into each of these models, then go to the MODELS tab. You will be directed to the Model Leaderboard page.

In the Model Leaderboard page you can see the best models in terms of forecasting quality and the Training time. At the bottom you can see all models listed with their forecasting quality, training time and whether the model is used to perform continuous forecasting.

Model Leaderboard pageModel Leaderboard Page

If you want to get detailed insights into a model, then click on the model and go to its INSIGHTS tab. Here you can see the model’s performance for,

  1. Specific groups and levels defined during Step 4: Define granularity levels above: For example if you want to see the performance of a model on a particular product at a specific store, then select the product from Product Group drop down and select the store from Location Group drop down.

  2. Overall model performance.

This page shows a comprehensive insights into model performance for the specific group using following charts.

  1. Actual vs Forecast charts for multiple latest backtesting periods for a specific group (for e.g.: item_nbr = 1047679 for all locations)

  2. Evaluation metric values for these backtesting periods (default is forecasting quality) for the specified level (for e.g.: item_nbr level for all locations)

  3. Average evaluation metric values for each step in the horizon period (Since you selected daily forecast for a month period, this chart shows forecasting quality for day 1 -31 in a month averaged across multiple backtesting periods for the specified level (for e.g.: item_nbr level for all locations)

Also you can see the overall model performance in two charts.

  1. Evaluation metric values for the backtesting periods

  2. Average evaluation metric value for each step in the horizon period

🎓 To learn more about backtesting in demand forecasting apps, read What is backtesting?

Model performance for the specific groupModel performance for the specific group

Overall model performanceOverall model performance

Setting up continuous forecasting

Once the app is ready, you can see the forecast for the last period on the app summary page. However, typical demand forecasting applications require continuous forecasting at regular intervals.

💡The continuous forecasting frequency is setup for demand forecasting applications during Define business requirements step in app builder in the Engine.

To enable continuous forecasting, click on Select models under the message Select models to enable continuous forecast in the app summary page. There you will see the list of trained models. Then you can select one or models to perform continuous forecasting.

Click  Select models to enable continuous forecastClick Select models to enable continuous forecast

Select the models for continuous forecastSelect the models for continuous forecast

Then you will need to configure how to provide data required for future forecasts. Here you can provide input sources such as databases where the Engine will fetch the required data automatically and perform the forecasts.

Configure input sources for continuous forecastingConfigure input sources for continuous forecasting

Once these inputs are provided, you can get forecasts in regular time intervals you set up during the App building stage.

🎓 For more information on continuous forecasting, read Setting up continuous forecasting

🎓 If your forecast is overdue, read Providing data for an overdue forecast

Conclusion

This article demonstrated a convenient and easy-to-use Demand Forecasting ML Solution Template for retail businesses using the AI & Analytics Engine. This solution can be extremely useful in many demand forecasting scenarios without requiring extensive technical expertise in machine learning or coding.