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.
Este exercício faz parte do curso
Forecasting Product Demand in R
Instruções do exercício
- 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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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)