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

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.

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

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.

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.

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).

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:

Day of the week. Month. Day of the month. Promotion. Previous day promotion. State holidays. School holidays. Previous 1-day sales. Previous 2-days sales. Previous 3-days sales. Previous 4-days sales. Previous 5-days sales. Previous 6-days sales. Previous 7-days sales.

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

The only target variable, or predictor, is:

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".

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.