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.
Cet exercice fait partie du cours
Forecasting Product Demand in R
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
predictfunction and theMET_sp_validdata frame. - Exponentiate your forecast and create an xts object.
- Calculate the MAPE using the
MET_sp_vobject for your validation set. YourMET_sp_validdata frame won't help here as it has all log prices and you want the MAPE on actual prices.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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)