CommencerCommencer gratuitement

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

Afficher le cours

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 the MET_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. Your MET_sp_valid data 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)
Modifier et exécuter le code