# Best regression model to use for sales prediction

I have the following variables along with sales data going back a few years:

• date # simple date, can be split in year, month etc
• shipping_time (0-6 weeks) # 0 weeks means in stock, more weeks means the product is out of stock but a shipment is on the way to the warehouse. Longer shipping times have a siginificant impact on sales.
• sales # amount of products sold

I need to predict the sales (which vary seasonally) while taking into account the shipping time. What would be a simple regression model that would produce reasonable results? I tried linear regression with only date and sales, but this does not account for seasonality, so the prediction is rather weak.

Edit: As a measure of accuracy, I will withold a random sample of data from the input and compare against the result.

Extra points if it can be easily done in python/scipy

Data can look like this

--------------------------------------------------
| date           | delivery_time| sales          |
--------------------------------------------------
| 2015-01-01     | 0            |10              |
--------------------------------------------------
| 2015-01-01     | 7            |2               |
--------------------------------------------------
| 2015-01-02     | 7            |3               |
...

• What do you mean by taking into account the shipping time? Also it is better to randomly select the held-out data as you might have seasonality effect in such "last month" selection. – Guy Jan 12 '16 at 14:47
• @Guy thank you for pointing out the random selection. What I mean by taking into account shipping time is using it as an independent variable. – noobstats Jan 12 '16 at 15:14
• @Guy I edited the question to reflect the random selection of data. – noobstats Jan 12 '16 at 15:16

This is a pretty classic ARIMA dataset. ARIMA is implemented in the StatsModels package for Python, the documentation for which is available here.

An ARIMA model with seasonal adjustment may be the simplest reasonably successful forecast for a complex time series such as sales forecasting. It may (probably will) be that you need to combine the method with an additional model layer to detect additional fluctuation beyond the auto-regressive function of your sales trend.

Unfortunately, simple linear regression models tend to fare quite poorly on time series data.

• (+1) Time series modelling should be the approach which needs to be followed here! – Dawny33 Jan 13 '16 at 3:29

Did you try time series modelling? If not, then you should.

I tried linear regression with only date and sales, but this does not account for seasonality

The moving average model is something which would fit nicely to your dataset.

However, as you say that your model is exhibiting seasonality, you need to adjust the moving averages so that it takes the seasonality into account.

So, the best model for your dataset would be the SARIMA model. It is just the Auto-Regressive Integrated Moving Average (ARIMA) model but with seasonal adjustments.

Here is one of the questions which I have answered which further helps you understand minor seasonality and trend adjustments, along with the R code.

In some cases, neural networks trained with the back-propagation algorithm have shown better results than time series models. The back propagation algorithm searches for weight values that minimize the total error of the network over the set of training examples.

You may take a look at these links which describes what I've said in more detail :

1. Frank M Thiesing and Oliver Vornberger "Sales Forecasting Using Neural Networks"

2. The Backpropagation Algorithm