Calculating MAPE and MAE
You previously calculated the forecast for the metropolitan region total sales and stored it in the object forecast_MET_t
. You also have your validation data set stored in the object MET_t_valid
that covers the same first 22 weeks of 2017. Let's see how good your forecast is!
This exercise is part of the course
Forecasting Product Demand in R
Exercise instructions
- Convert the mean of your forecast (
forecast_MET_t$mean
) and validation data set (MET_t_valid
) to numeric values and save them asfor_MET_t
andv_MET_t
respectively. - Calculate the MAE of your forecast. Remember, this is the average of the absolute difference between the forecast and the true validation values.
- Calculate the MAPE of your forecast. This takes the same difference as the MAE, but divides it by the true validation values.
- Print both the MAE and MAPE.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Convert to numeric for ease
for_MET_t <- as.numeric(___)
v_MET_t <- as.numeric(___)
# Calculate the MAE
MAE <- mean(abs(___ - ___))
# Calculate the MAPE
MAPE <- 100*mean(abs((for_MET_t - v_MET_t)/___))
# Print to see how good your forecast is!
print(MAE)
print(MAPE)