SES vs naive
In this exercise, you will apply your knowledge of training and test sets, the subset()
function, and the accuracy()
function, all of which you learned in Chapter 2, to compare SES and naive forecasts for the marathon
data.
You did something very similar to compare the naive and mean forecasts in an earlier exercise "Evaluating forecast accuracy of non-seasonal methods".
Let's review the process:
- First, import and load your data. Determine how much of your data you want to allocate to training, and how much to testing; the sets should not overlap.
- Subset the data to create a training set, which you will use as an argument in your forecasting function(s). Optionally, you can also create a test set to use later.
- Compute forecasts of the training set using whichever forecasting function(s) you choose, and set
h
equal to the number of values you want to forecast, which is also the length of the test set. - To view the results, use the
accuracy()
function with the forecast as the first argument and original data (or test set) as the second. - Pick a measure in the output, such as RMSE or MAE, to evaluate the forecast(s); a smaller error indicates higher accuracy.
The marathon
data is loaded into your workspace.
This exercise is part of the course
Forecasting in R
Exercise instructions
- Using
subset()
, create a training set formarathon
comprising all but the last 20 years of the data which you will reserve for testing. - Compute the SES and naive forecasts of this training set and save them to
fcses
andfcnaive
, respectively. - Calculate forecast accuracy measures of the two sets of forecasts using the
accuracy()
function in your console. - Assign the best forecasts (either
fcses
orfcnaive
) based on RMSE tofcbest
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a training set using subset()
train <- ___(___, end = length(marathon) - ___)
# Compute SES and naive forecasts, save to fcses and fcnaive
fcses <- ses(___, h = ___)
fcnaive <- naive(___, h = ___)
# Calculate forecast accuracy measures
accuracy(___, ___)
accuracy(___, ___)
# Save the best forecasts as fcbest
fcbest <- ___