Get startedGet started for free

Forecasting with regression

1. Forecasting with regression

OK great! We have built a model, but how do we forecast with what we have?

2. Forecasting with Time Series

In time series modeling forecasting is easy. We use previous values in our data to predict future values. That is the lag nature of our models! If we use today to predict tomorrow, all I need to know is the demand today and I can forecast demand tomorrow.

3. Forecasting with Regression

Forecasting with regression gets a little more complicated. We are using factors to predict demand. Those factors are on the same time point. For example, if I use price today to predict demand today, then I need price tomorrow to predict demand tomorrow. Essentially, I need future, and possibly unknown, values of X to predict future values of Y! That can potentially complicate things. So what do we do?

4. Future Input Variables

How we handle future values of input variables depends on the variables themselves. Holiday and promotion variables are known ahead of time. I know exactly when New Year's will happen in 2018. I know ahead of time that a promotion is going to be run. None of those things are surprising me. Prices on the other hand can be more complicated. In some situations, ours for example, prices are set ahead of time. Prices are negotiated with venders 6 months in advance and cannot be easily changed. Is that limiting? Not really. Imagine if I agreed to sell bread for $3.99 for 6 months. However, two months in I am not seeing the demand I would like. I could run a promotion, maybe $1.00 off bread for 3 weeks to effectively "change" the price. We don't always know price ahead of time though. In those more complicated situations, we could always use the same time series modeling structure we did in Chapter 1 to forecast out prices too! That is beyond the scope of this course, but not too difficult. Just repeat Chapter one with prices!

5. Future Input Variables Example

Future values of holidays or promotions are easier to create since we know when they will happen! First, we create the date object for the 2017 Valentine's Day week in our validation data set. Then we build our xts object the same way we did in our training set. The only difference is the dates! We have the 22 week time period in our validation data set created in our dates_valid object. Then we merge these dates with our xts object and fill in the blanks with zeroes like we did before. We also need our prices! Here we are going to assume that prices were set 6 months in advance, so our validation data set prices are actually valid inputs for predicting future demand. Once we have our future indicator variable and our future prices we just build them into a data frame like we did with our regression model. Notice an IMPORTANT thing here. The column names! The column names are the same in this prediction data set as with the training data set. That is important.

6. Future Regression Example

Now all we have to do is use the predict function. What are our two inputs? The first input is the regression model object. The second input is the data set that we want to score. The output from this will be our predictions! Careful though. Let's take a look at them. These are still on the log scale. We need to reverse that with the exponential function. Now those look like good forecasts!

7. Let's practice!

Now you go do the same thing for the high end products in the metropolitan region!