Evaluating forecast accuracy of seasonal methods
As you learned in the first chapter, the window()
function specifies the start
and end
of a time series using the relevant times rather than the index values. Either of those two arguments can be formatted as a vector like c(year, period)
which you have also previously used as an argument for ts()
. Again, period refers to quarter here.
Here, you will use the Melbourne quarterly visitor numbers (visnights[, "VICMetro"]
) to create three different training sets, omitting the last 1, 2 and 3 years, respectively. Inspect the pre-loaded visnights
data in your console before beginning the exercise; this will help you determine the correct value to use for the keyword h
(which specifies the number of values you want to forecast) in your forecasting methods.
Then for each training set, compute the next year of data, and finally compare the mean absolute percentage error (MAPE) of the forecasts using accuracy()
. Why do you think that the MAPE vary so much?
Este ejercicio forma parte del curso
Forecasting in R
Instrucciones del ejercicio
- Use
window()
to create three training sets fromvisnights[,"VICMetro"]
, omitting the last 1, 2 and 3 years; call thesetrain1
,train2
, andtrain3
, respectively. Set theend
keyword accordingly. - Compute one year of forecasts for each training set using the
snaive()
method. Call thesefc1
,fc2
, andfc3
, respectively. - Following the structure of the sample code, compare the MAPE of the three sets of forecasts using the
accuracy()
function as your test set.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# Create three training series omitting the last 1, 2, and 3 years
train1 <- window(visnights[, "VICMetro"], end = c(2015, 4))
train2 <- ___
train3 <- ___
# Produce forecasts using snaive()
fc1 <- snaive(___, h = ___)
fc2 <- ___
fc3 <- ___
# Use accuracy() to compare the MAPE of each series
accuracy(fc1, visnights[, "VICMetro"])["Test set", "MAPE"]
___
___