Forecasting time series
After using HoltWinters
to build a time series smoothing model, we can now forecast future values based on the smoothing model. In this recipe, we introduce how to use the forecast
function to make a prediction on time series data.
Getting ready
In this recipe, you have to have completed the previous recipe by generating a smoothing model with HoltWinters
and have it stored in a variable, m.pre
.
How to do it…
Please perform the following steps to forecast Taiwan Semiconductor's future income:
- Load the
forecast
package:> library(forecast)
- We can use the
forecast
function to predict the income of the next four quarters:> income.pre <- forecast.HoltWinters(m.pre, h=4) > summary(income.pre) Forecast method: HoltWinters Model Information: ...
Get R for Data Science Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.