Naive forecasting methods
As you learned in the video, a forecast is the mean or median of simulated futures of a time series.
The very simplest forecasting method is to use the most recent observation; this is called a naive forecast and can be implemented in a namesake function. This is the best that can be done for many time series including most stock price data, and even if it is not a good forecasting method, it provides a useful benchmark for other forecasting methods.
For seasonal data, a related idea is to use the corresponding season from the last year of data. For example, if you want to forecast the sales volume for next March, you would use the sales volume from the previous March. This is implemented in the snaive()
function, meaning, seasonal naive.
For both forecasting methods, you can set the second argument h
, which specifies the number of values you want to forecast; as shown in the code below, they have different default values. The resulting output is an object of class forecast
. This is the core class of objects in the forecast
package, and there are many functions for dealing with them including summary()
and autoplot()
.
naive(y, h = 10)
snaive(y, h = 2 * frequency(x))
You will try these two functions on the goog
series and ausbeer
series, respectively. These are available to use in your workspace.
This is a part of the course
“Forecasting in R”
Exercise instructions
- Use
naive()
to forecast the next 20 values of thegoog
series, and save this tofcgoog
. - Plot and summarize the forecasts using
autoplot()
andsummary()
. - Use
snaive()
to forecast the next 16 values of theausbeer
series, and save this tofcbeer
. - Plot and summarize the forecasts for
fcbeer
the same way you did forfcgoog
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Use naive() to forecast the goog series
fcgoog <- naive(___, ___)
# Plot and summarize the forecasts
___(___)
___(___)
# Use snaive() to forecast the ausbeer series
fcbeer <- ___
# Plot and summarize the forecasts
___
___
This exercise is part of the course
Forecasting in R
Learn how to make predictions about the future using time series forecasting in R including ARIMA models and exponential smoothing methods.
In this chapter, you will learn general tools that are useful for many different forecasting situations. It will describe some methods for benchmark forecasting, methods for checking whether a forecasting method has adequately utilized the available information, and methods for measuring forecast accuracy. Each of the tools discussed in this chapter will be used repeatedly in subsequent chapters as you develop and explore a range of forecasting methods.
Exercise 1: Forecasts and potential futuresExercise 2: Naive forecasting methodsExercise 3: Fitted values and residualsExercise 4: Checking time series residualsExercise 5: Training and test setsExercise 6: Evaluating forecast accuracy of non-seasonal methodsExercise 7: Evaluating forecast accuracy of seasonal methodsExercise 8: Do I have a good forecasting model?Exercise 9: Time series cross-validationExercise 10: Using tsCV() for time series cross-validationWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.