Building a sales prediction model for a retail store

By Pablo Martin and Roberto Lopez, Artelnics.

Sales forecasting is an essential task for the management of a store.

Machine learning can help us discover the factors that influence sales in a retail store and estimate the number of sales that it will have in the near future.

In this post, we use historical sales data of a drug store to predict its sales up to one week in advance.


  1. Data analysis.
  2. Model training.
  3. Testing analysis.
  4. Model deployment.
  5. Conclusions.

Data analysis

The first step of the analysis is to study the data set, which contains the sales information from the drug store.

The next time series chart shows the number of sales by month.

Sales per month in a retail store

As we can see, most of the sales are made between March and July. Then, the number of sales decreases until December, when it grows again.

The next chart shows how sales are distributed throughout the month.

Sales by day of month in a retail store

In this case, the days of the beginning of the month are the ones with higher activity. After the middle of the month, the sales remain stable.

It is also essential to take a look at the number of sales by weekday. The next time series chart shows the sales in this shop from Sunday (1) to Saturday (7).

Sales by weekday in a retail store

Sunday is the day preferred by the customers to buy in this retail shop. During the rest of the week, the sales decrease from Monday to Wednesday and increase from Wednesday to Friday. Saturday is the day with the least number of sales.

The next step is to select and prepare the variables that we are going to use.

The following list shows the input variables or predictands:

  1. Day of the week.
  2. Month.
  3. Day of the month.
  4. Promotion.
  5. Previous day promotion.
  6. State holidays.
  7. School holidays.
  8. Previous 1-day sales.
  9. Previous 2-days sales.
  10. Previous 3-days sales.
  11. Previous 4-days sales.
  12. Previous 5-days sales.
  13. Previous 6-days sales.
  14. Previous 7-days sales.

As we can see, the number of inputs is 14.

The only target variable, or predictor, is:

  1. Next 7 days sales

Once the variables are defined, we can calculate the dependencies between all the inputs and the target.

The next chart shows the linear correlations between each input and the target variable "Sales".

Correlations between variables and sales in a retail store.

The number of sales of the same weekday of the previous week, the weekday and the state holidays is highly correlated with the number of sales.

Model training

After defining the variables that we are going to use for the analysis, it is time to use Neural Designer to build the predictive model for the sales of the store.

The next image shows a representation of the neural network that we use for the predictive analysis.

Neural network to forecast sales in retail stores

The information on the date, promos, holidays, and sales of the previous week enters the neural network through the left layer. Then, it is analyzed by perceptrons in the middle's layer to find the patterns that determine the number of sales given by the last layer.

Now, the neural network is ready to be trained using the Quasi-Newton algorithm. To find more information about this and other optimization algorithms, you can read 5 algorithms to train a neural network.

Testing analysis

Before using the model to forecast the sales, the last step is to determine its predictive power on an independent set of data that has not been used before for the training. The next chart shows the linear regression analysis between the scaled output of the neural network and the corresponding scaled targets.

Regression to forecast sales in retail stores

The next table shows the parameters of the previous linear regression analysis.

Intercept -0.041
Slope 0.902
Correlation 0.908

The intercept and the slope are near 0 and 1, respectively. There is a correlation between outputs and targets of almost 91%. This means the model is predicting well this set of data.

As a consequence, the model is ready to be moved to the deployment phase.

Model deployment

Once the model has been tested, it can be used to predict the sales of the shop one week in advance.

Retail store sales predictions

As we can see, the next week's Sunday is the day when most of the sales are expected. During the rest of the week, the number of sales will remain stable, and they will decrease slightly with respect to the previous week.


During this article, we have developed a predictive model that can help retailers determine the number of sales they are going to make in the future.

By using this model, retailers can plan the number of products that they are going to need. As a consequence, the system will allow them to increase their profits.

You can use Neural Designer to build predictive models from your data and forecast your own company's sales or test it using the data set you can find below.


Related posts:

Subscribe To Our Newsletter