Sales forecasting and stock optimisation in supply chain with Machine Learning technology

Sales forecasting and stock optimisation in supply chain with Machine Learning technology

9 min read Jul 12, 2020

Stock optimisation is an important KPI in supply chain businesses, as it translates to cash flow directly. On the one hand, constantly high stock levels (overstocking) indicate that money spent on stock is money not spent on potential growth while on the other hand, low stock levels (frequent stock-out events) indicate that money might be getting lost on missed sales.

The main objective of stock optimisation is to decrease the stock levels but still have the right product at the right place at the right time to prevent losing a potential sale or missing a manufacturing window. 

Most commonly, companies employ people who are dedicated to placing orders. They are required to get familiar with the items, keep track of sales and changes in the sales behaviour, and analyse events that impact sales to fill the purchase order per item. They must take into account both objectives – maintaining a low stock level while decreasing stock-outs. This is a relatively effective and efficient approach when dealing with a small number of items to order. However, once the number of items per person increases, so does the complexity of making the right ordering decision. The number of parameters to analyse, observe and consider increases to the level, which is labour intensive, time-consuming and in most cases not possible for the human brain to do efficiently for all items. This results in frequent stock-outs which trigger higher orders that end up with excessive stock levels and even in dead stock. 

The need to facilitate the ordering process has accelerated the research and development of various approaches and tools that can assist the buyer. Most used are rule-based tools which cannot automatically adapt to changes in the market (demand). To overcome this problem, we developed the Sales Forecasting and Stock Optimisation module (SF & SO) for the BE-terna ML Platform, which employs machine-learning techniques on multiple data sources to detect changes and enable automatic adaptation. 

BE-terna ML Platform SF & SO module generates vendor-specific purchase orders, produces explanatory reports and enables revision of generated orders so the buyer can accept the recommendation immediately or correct it. The goal of the ML platform is to generate automatic order recommendations that will: 

  • Improve ordering efficiency by decreasing the time needed to fill orders 
  • Result in decreased inventory level (stock optimisation) for increased cash flow 
  • Result in a lower number of stock-out events (improved service) for increased profit 

To achieve all of the benefits mentioned above, it is crucial to provide the buyer with a user-friendly and familiar explanation of the results. We use a BI tool for interactive result drill-downs. 

The success of any AI tool depends on the trust and acceptance of the people who will be using it, so the user experience is just as important as the accuracy of the ML platform. 

The workflow

BE-terna ML platform’s SF & SO module high-level workflow is presented in Figure 1. It also includes a stock monitoring module, vendor calendar monitoring, data cleansing (historic anomalies), detection of active items, constraints, etc.

The module then selects the vendor or an item for ordering. Since the monitoring module is a story in itself, this blog post will only focus on the SF & SO module. The input comes from various data sources, such as ERP and BI systems and third-party data such as weather, transport, events, etc. The input data is pre-processed into time windows (by minute, daily, weekly, monthly, yearly, etc.) and fused into a single object representing the exact timeframe. The data is fed into the sales forecasting module which first identifies the type of item (fast-moving, seasonal, slow-moving, new item, promotional, etc,) and trains several machine-learning models using a different set of features and self-evaluations on specifically assigned historic data sets. The best performing model is used for forecasting sales for the next period (the length of the period depends on the business). The items enhanced with forecasts are sent into the order scheduler which considers vendor-specific constraints and requirements together with forecasts and simulates the results to optimise the order value which is set as an order recommendation. The recommendations are sent into the ERP system to be revised by the buyers and into the BI tool which contains additional data to make results more understandable. Figure 1. High-level workflow of the BE-terna ML platform's SF & SO module. 


Figure 1. High-level workflow of the BE-terna ML platform's SF & SO module.

Use-case evaluation

Before you start implementing BE-terna ML platform’s SF & SO module into your business process we recommend you carry out a test run by selecting a set of items (50-500 items) and evaluating the potential benefits of the optimisation. Here, we report the results of one such test which later resulted in a successfully deployed module accepted by the buyers. 

Dataset: we received sales and order data for 250 items. The dataset contained realistic per-type distribution of items. The dataset contained fast and slow moving products, seasonal goods, stock-outs, new and promotional products, tenders and items with a short expiration date. 

Using the small sample of items, we tried answering the following questions: 

  • How accurate are the forecasts
  • Can we decrease stock-outs
  • Can we decrease the stock levels

We evaluated all 250 items and presented the answers. 

The accuracy of the forecasts was evaluated in Mean Absolute Error (MAE) and mean absolute percentage error (MAPE) commonly used in regression tasks. Since MAE is item-specific and the list is long, we report only items with average MAPE over 20%. The forecasts are then used in the order scheduler which outputs the orders that contribute to ordered stock and potential stock-outs. Presented below are examples of a fast-moving (Figure 2) and seasonal item (Figure 3). 

We present the results of a forecast (left-hand chart in Figure 2) where the green line represents the real sales and the blue line is the forecast. MAPE is 11%. The forecast is used for stock optimisation presented on the right-hand chart where the green line is the real stock level, the blue line is the optimised stock level, the dark blue area is the amount of decreased stock. We can observe that the green line (real stock level) increases with each order (4 times a month). On the other hand, our simulation has the first order on 23 June and the ordered amount is significantly lower since we automatically re-evaluated the safety-stock according to the forecasting performance and set it significantly lower. The stock level has clearly decreased. 


Figure 2. Fast-moving item forecast and stock optimisation. We can observe accurate forecast and a significant decrease in stock level. 


Figure 3. Seasonal item forecast and stock optimisation. We can observe avoided stock-out and decreased stock at the end of the month. 

The seasonal item is shown in Figure 3. MAPE of the forecast on the right is 8%. The forecast is used for stock optimisation presented on the right-hand chart where the green line is the real stock level, the blue line is the optimised stock level, the light blue area is the amount of increased stock and the dark blue area is the amount of decreased stock. We can observe that at the beginning of the month, we forecast sales, made an order and increased the stock (light blue area). The stock is lower. However, on 11 June, the green line shows a stock-out event whereas ours (blue) does not. Because of the stock-out, they ordered too much. 

By the end of the month, the simulation maintained lower stock levels while avoiding the stock-out. 

Overall stock-outs

An evaluation of all 250 items resulted in answers to the questions related to stock-outs and stock level. We evaluated the number of stock-out events that occurred to our client and several stock-outs created by the SF & SO module. The results are shown in Figure 4. Their actions generated at least one stock-out event for 44% of items during the evaluation year while the SF & SO module generated at least one stock-out for 14% of items. 

This indicates that we can decrease stock-outs, more specifically we can generate automatic orders for 86% of items. 


Overall stock levels

The evaluation showed that we decreased the stock in some cases and increased it elsewhere to avoid the stock-outs. Per item stock difference is shown in Figure 4. The left side represents the decreased stock and the right side represents the increased stock. Figure 4 We decreased the stock level between 25% and 60%. The increased stock at the end of the tail represents orders which avoided stock-outs that occurred in real data. 


FIgure 4: Overall stock-outs

User interface

An important factor in the adoption of AI projects is the user experience and the intelligibility of results which helps build trust in the system. We send the results directly into the ERP system where the buyers can correct the amounts or simply accept the recommendations. Additionally, we display the results in Qlik as shown below . We visualise the actual and forecast sales and display the current and recommended stock levels. We also present some statistical parameters that buyers use when making orders so they can evaluate the forecast if required. From experience, the buyers build trust in the system using this application and after a few orders they open Qlik only to check the sales trends and see the explanation for what they think are “unusual” recommendations. 



Stock optimisation represents the easiest proven path to significant cost savings and increased revenue. Using a tool such as BE-terna ML platform Sales Forecasting and Stock Optimisation module can decrease stock-levels and stock-outs while increasing the efficiency of filling orders since the majority of items can be fully automatised. Here we have shown only stock optimisation processes for a distribution centre. 

However modelling the customers can additionally increase the forecast accuracy, service level and customer satisfaction.

Om forfatteren

Božidara Cvetković

Lead Data Scientist