Demand forecasting with SmartPredict
Forecasting demand in the retail sector plays a decisive role in trade. As analytical statistical tools reach their limits in unusual situations, it is essential to make use of Artificial Intelligence. However, achieving AI projects is complex. Hence the advantage of using SmartPredict platform which allows you to carry out any type of AI project quickly and easily without coding.
This blog then reports on a project "Demand forecasting with SmartPredict" in 3 sections:
- the interest of the project
- presentation of the project
- realization of the project in SmartPredict
2- Interest of the project
For any business operating in the trade sector, forecasting demand is essential for:
-the forecast of market trends in the quantity and quality of items in order to supply stores according to the season
-the categorization of items according to their sale rate
- the stock and department management
-the balance between supply and demand
- the production forecast to avoid losses.
3- Presentation of the project
The project involves training and deploying Machine Learning that will predict the number of daily sales or the daily demand for a product in a store for a year. The entire project will be performed on SmartPredict, the ideal platform for easily carrying out all Artificial Intelligence projects. We then deal with a "time series forecasting".
In the end, by presenting quantities of daily sales of bread in a year, for example, our model returns the daily sales in the following year, as shown in the figure below.
These predicted sales values can be retrieved and visualized.
To train our ML, we have at our disposal a dataset that presents the daily sales of the 50 items in 10 stores for 5 years (2013-01-01 / 2017-31-12).
The originality of the project lies in the technology that we use (which is Artificial Intelligence) and especially on the SmartPredict platform (beta version) which allows us to carry out AI projects in an innovative way. In fact, instead of coding, we only have to associate modules to achieve a "FLOWCHART" in order to train and deploy our ML. The only principle is to know and verify the type and size of the "inputs" and "outputs" between each module.
The flowchart that will train our Machine Learning corresponds to the following figure:
The flowchart used to deploy our trained model is as follows:
It should be mentioned that building flowchart requires notions in ML, but with the future version of Smartpredict ( which will be released on July 2020), several tasks (data processing, modeling, training, deployment) will be automated and we will only have to present our data and a trained and deployed model predicts the state of our sales in the future.
4- Realization of the project in SmartPredict
Every machine learning project is carried out in three stages with Smartpredict (beta version):
- build a flowchart in Build Tab to train the model (Machine learning)
-build another flowchart in Deploy Tab to deploy the trained model
- test our deployed model in Test Tab
Firstly, you have to create an account, upload the data into Smartpredict, and have a view on it with the DatasetProcessor App
Step 1: Train model in Build Tab
The flowchart that we build in the Build tab allows us to train our model and evaluate it.
To do so, we drag and drop modules available in the Core Module. Then we set and interconnect them.
The figure below summarizes the principle of the set of elements that constitute any flowchart in the Build tab.
- The "data preprocessing" depends on the structure of the data and the transformation required for it to train our model. So when there is no appropriate module that matches the desired operation, we can create our own module with a custom Module, with which we define our own functions in Python code.
So for the project, the following modules were interconnected in successions :
- our "train" dataset retrievable from the "Datasets" sub-tab;
- two "Dataset Processor" modules that filter rows to return only sales data from a single "item" in a single "store";
- one "Feature Selector" module that selects the features with which our model will be trained;
- "time-series-to-supervised" module that we customized which transforms our data as described in this article. This module returns 4 "outputs": Xtrain, Ytrain, Xtest, Ytest;
- our ML model "XGBoost Regressor" ;
- one "Trainer ML models" which trains the learning machine model with the Xtrain, Ytrain data;
- one "Evaluator for ML" which evaluates our trained model with Xtest, Ytest with the metric Mean Absolute Error (MAE).
It is essential to register our trained model by an ItemSaver module, which is retrieved from the "Trained Model" drop-down list, useful when building the flowchart in the Deploy tab.
The figure below provides information on the parameters of each module.
The following Gif shows us the beginning of the construction of the flowchart.
Once built (see Fig. 1) click on "Run" and each process runs successively until displaying the MAE value = 4.22, which indicates the average of all the absolute errors recorded (Prediction Error = Actual Sales Value - Predicted Sales Value).
Step 2: Deploy our model in the Deploy tab
The deployment of a trained model consists of creating a flowchart that, once launched, will allow our model to be functional as a web service: the model will return a prediction according to the data (features) we give it.
The figure below summarizes the general principle of all the modules that make up any flowchart in the Deploy tab.
- Thus all flowchart in Deploy necessarily starts with a "Web SERVICE IN" module, which receives the data in JSON format via REST API.
- The modules that follow will have the task of transforming this data (features) so that they can be processed by the model to make the prediction. It should be mentioned that the format of the input data during training and deployment must be the same.
So we used successively :
- DataFrame loader/converter that receives JSON data as a "dictionary" and transforms it into Dataframe;
- Feature selector which returns the data in an array;
- timeseries_time_step that we customized to find the data structure when training the model;
- The modules that end any flowchart in the Deploy are necessary:
- The trained model that we retrieve from the trained model;
- Predictor ML models that returns the data predicted by the model
- Web Service OUT that returns data in JSON format with REST API
The following figure shows the configuration of these modules for this project:
The following excerpt shows the beginning of the flowchart construction in Deploy Tab.
Une fois construite (cf Fig 03) on clique sur la fusée, et un token et un URL nous est fourni pour accéder à notre web service.
Step 3: Test our model in the Test tab
Once tested, our project could be saved as a template.
Normally we use software like Postam to test our template, but fortunately, with SmartPredict we can do everything on one platform until the test.
Now that the trained template is already available as a Web Service, all we have to do is enter the previous year's sales so that it can predict the daily sales for the following year (see Fig 01). Indeed, it is the sales data that we used as "features" to train the model.
AI is now a tool that is as crucial as it is effective in any sector, especially in the commercial sector where daily sales quantities can be predicted. Now the application of this technology is convenient thanks to the SmartPredict platform.
All steps explained in section 4 will be automated with the future version of SmartPredict, which will be released in July.
So stay connected and be the first to innovate your business with the next version of SmartPredict.