Sales Forecast using multiple Predictors
An accurate forecast of your sales and can help you to manage inventory more efficiently. However, it is hard to account for the various factors that affect sales, to capture seasonal changes, and the pattern changes over time. Thanks to Artificial Intelligence, and more specifically deep learning, this task has been made much more accessible and we can now predict the sales efficiently using a neural network that analyses sequential data and temporal data.
If that last sentence confused the hell out of you, well, fear not. This article is not going to be a highly technical plunge into the nitty-gritty of deep learning networks. (If that’s your thing however do check out this article which explains the problem from a more technical perspective).
This article will focus more on the what using a artificial neural network entails, and what it can mean for a business, how it can analyse multiple features to make an accurate prediction. We will be demonstrating this using a publicly available dataset.
First off, we propose the problem we would like to solve. Our goal is to forecast the total sales for a retail chain across all its stores. Given sales data 2 months. Sounds good? Let’s take a look at our data. This data was extracted from Kaggle dataset — Rossman Sales Data. Let’s take a look at our data:
Rossman Store Sales Data
The figure shows the first 10 rows of the data. The column ‘Promo’ tells whether there was a promotional offer going on during the day. The column ‘DayOfWeek’ specifies what day it was — 1= Monday, 2= Tuesday…7=Sunday and so on. The number of customers and the total sales are both targets we would like to predict for the future.
This is a very simplified approach and we have neglected factors such as geographic locations of individual stores and whether there was a holiday that affected each store. But since we are interested in how the chain is doing as a whole, our data model should be able to predict sales with fairly accurate results.
Before we go ahead and build our model let’s explore the data to unravel any relations the data might hold. We would also like to see any general trends in the sales data over time. In particular, we are looking for any trends in terms of seasonality, or based on the day of week or whether there was a promotional offer on a given day.
1. Day Of The Week
Sales on each day
The plot given above shows the sales on each day. Taking a close look, we see that there is a trend to this data — The sales seem to plummet every 7th day. On a closer inspection we can see that these dates corresponds to Sundays. It takes off again on Monday, and Mondays seem to be the best day for business.
Indeed, when we average the sale for each day (given below) we see this clearly.
Sales by day
- Yearly Trend
Let’s see if there’s a yearly trend. Plotted below is the average sales for each month. We see that sales peak towards the last few days of the year. September and October are not great months for sales either. However there is no periodicity here.
Promotions have a big impact. The sales almost doubled when a promotion was available:
Building Our Model
We will train our model to predict the sales based on the data, and we will explore if our predictions are able to factor in the relations we mentioned here
A neural network will be able to model the sales on a particular day as a function of the sales data of the days prior to it. However, some important factors to be considered :
- Our model should be able to detect dips and peaks in sales data based on external factors — like promo code.
- There is a periodicity in this data. The sales data tend to be periodic by the week. So after every 7 days we see a similar trend.
To consider all these into account, we use a novel architecture called LSTNet- which uses a convolutional neural network that analyses how each variable affects the sales on that day. We will use this in conjunction with a Recurrent Neural Network that analyse data by each day. Further we use another layer which factors in the fact that the sales trend is periodic by each week.ta
The features that we passed to the network are -
- Sales Data on each day ( Integer)
- The day of the week ( 1 = Monday ..to 7= Sunday)
- Promotion ( 1= Yes, 0 = No)
It’s worth mentioning here that training a model requires finding out the accurate hyper-parameters such as the number of epochs, number of timesteps to consider for making an accurate prediction. If this number is too high, the model runs the risk of over-fitting and taking too much runtime. Too low and the model will not be able to converge, and make an accurate prediction. However these details are omitted here and are discussed in this article.
How close did we get?
Having trained our model and collected the results, it’s time to analyse them to see how our model is performing.
The graph below shows the predictions by each day, where the blue line represents the prediction:
[et_pb_image src="https://www.aihello.com/resources/wp-content/uploads/2019/05/0_gfX_KfeG6Kxl99Xh.png" _builder_version="3.22.5"][/et_pb_image][et_pb_text _builder_version="3.22.5"]
Predictions by day
The periodicity is captured almost flawlessly by the model, and the peaks on each day are very close. Some aberrations in the peak sales value occur, but this could be due to holidays which we have not factored in yet.
Here’s the total sales calculated for each week. Calculating this on a weekly basis makes sense because stocks and strategy can usually be planned on a weekly basis in the retail market industry:
[et_pb_image src="https://www.aihello.com/resources/wp-content/uploads/2019/05/0_sWJF3KCCb7s46adv.png" _builder_version="3.22.5"][/et_pb_image][et_pb_text _builder_version="3.22.5"]
Predictions for each week
The blue bar represents the prediction and the red bar represents the actual sales value.We can see that the error is minimal, and the prediction is accurate in most cases, and this is without even considering factors such as holidays externally.
How can you use this approach to fit your business problems?
This demonstration was rather a simplistic approach to the forecasting problem although with very promising results. There may be multiple factors that would affect the sales of an enterprise.
In the case of our dataset, factoring in individual store locations and the holidays that affect each store could have made our predictions better. The geographic location would have helped us to see which areas performed better and modify the strategy of the organisation.
In case of an e-commerce seller who is interested in seeing the trend for each product, the factors affecting their sales might include the price of the product, the location of shipping and origin, and even the weather conditions( if they are into selling, say, winter boots). Here we have demonstrated that these factors can be easily fed into a neural network to unravel these mysterious correlations and gain better understanding of future sales.
Additionally, we can also tune the periodicity, to look for long-term or short-term patterns. In our case, the pattern was weekly. It could be every quarter or even every year. The beauty of the LSTNet model we used is that all this additional information can be fed into the network.
Well, I hope you enjoyed reading this article and that it helped you gain an understanding about how you can tap into the power of AI to boost your business.
Please feel free to ask away any questions you might have in the comment section!