Build regression forecast for new product
We saw in a previous exercise that regression forecasts are also worth building! Your workspace has some preloaded things to help. You have a data frame called MET_sp_train
with the variables log_sales
, log_price
, christmas
, valentine
, newyear
, and mother
in it. Your workspace also has a validation data frame MET_sp_valid
for predictions.
This exercise is part of the course
Forecasting Product Demand in R
Exercise instructions
- Build a regression model predicting log of sales with log of price and all the holiday and promotion variables.
- Forecast out the model with the
predict
function and theMET_sp_valid
data frame. - Exponentiate your forecast and create an xts object.
- Calculate the MAPE using the
MET_sp_v
object for your validation set. YourMET_sp_valid
data frame won't help here as it has all log prices and you want the MAPE on actual prices.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Build a regression model on the training data
model_MET_sp_full <- lm(___ ~ ___ + ___ + ___ + ___ + ___, data = ___)
# Forecast the regression model using the predict function
pred_MET_sp <- ___(___, newdata = ___)
# Exponentiate your predictions and create an xts object
pred_MET_sp <- ___(___)
pred_MET_sp_xts <- ___(___, order.by = ___)
# Calculate MAPE
MAPE <- mape(___, ___)
print(MAPE)