Get startedGet started for free

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:

  1. 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.
  2. 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.
  3. 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.
  4. To view the results, use the accuracy() function with the forecast as the first argument and original data (or test set) as the second.
  5. 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

View Course

Exercise instructions

  • Using subset(), create a training set for marathon 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 and fcnaive, respectively.
  • Calculate forecast accuracy measures of the two sets of forecasts using the accuracy() function in your console.
  • Assign the best forecasts (either fcses or fcnaive) based on RMSE to fcbest.

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 <- ___
Edit and Run Code