ellisp / forecastHybrid

Convenient functions for ensemble forecasts in R combining approaches from the {forecast} package
GNU General Public License v3.0
79 stars 23 forks source link

About how to use "cvts" to execute prediction like function "forecast" #70

Closed chaojieji closed 7 years ago

chaojieji commented 7 years ago

I have an question about how to execute prediction after running function "cvts". Through this function, I just get the residuals in each iterations. But, now, I'm eager to use the established model to predict the value in the next cycle. Or, I didn't understand the exact meaning about the function "cvts". Please help me. Thanks for your any suggestions and attentions.

dashaub commented 7 years ago

cvts() isn't meant for building a model for forecasting but rather for model selection. For example, suppose we are deciding whether we should use the ets() or auto.arima() model for forecasting on the AirPassengers timeseries. Which one do we think will produce better forecasts?

> accuracy(cvts(AirPassengers, ets, verbose = FALSE, maxHorizon = 12))
                             ME      RMSE      MAE
Forecast Horizon  1    4.377438  7.555887  5.68249
Forecast Horizon  2  -12.187395 14.845559 12.54877
Forecast Horizon  3  -16.874021 28.158767 23.36179
Forecast Horizon  4   -1.002180 17.406416 13.10624
Forecast Horizon  5   13.253368 23.568979 18.37369
Forecast Horizon  6   25.314886 28.347798 25.31489
Forecast Horizon  7   40.513768 46.443109 40.51377
Forecast Horizon  8   44.598501 51.191551 44.59850
Forecast Horizon  9   17.074692 27.040711 21.04146
Forecast Horizon  10  18.610941 27.093169 19.14697
Forecast Horizon  11  15.617927 24.988113 17.43594
Forecast Horizon  12   9.823385 27.006400 18.84148
> accuracy(cvts(AirPassengers, auto.arima, verbose = FALSE, maxHorizon = 12))
                             ME      RMSE       MAE
Forecast Horizon  1   0.8441219  9.055441  6.570835
Forecast Horizon  2  -2.2596437 13.799534 11.890191
Forecast Horizon  3  -3.8235963 32.134469 26.890897
Forecast Horizon  4   4.4134719 24.957100 17.012638
Forecast Horizon  5   6.2861460 27.506572 20.600639
Forecast Horizon  6  11.1643157 21.856905 19.078809
Forecast Horizon  7  18.8806005 27.619471 21.079767
Forecast Horizon  8  19.0746350 30.452813 25.989962
Forecast Horizon  9   5.7406470 31.497807 26.055140
Forecast Horizon  10  3.0252482 23.409419 18.723048
Forecast Horizon  11 -4.2546959 30.334933 24.984884
Forecast Horizon  12 -3.5490471 36.887334 29.833668

We see that the auto.arima() model has lower forecast errors for shorter forecast horizons as measured by RMSE and MAE but higher errors for longer horizons. If we are building a hybridModel() and want to include all of the individual models, these errors calculated by cvts() can be used for determining weights to assign to each individual model.

> hm <- hybridModel(AirPassengers, weights = "cv.errors", verbose = FALSE, errorMethod = "MAE")
> hm$weights
auto.arima        ets     thetam     nnetar       stlm      tbats 
 0.1273916  0.2017122  0.1659518  0.1524108  0.2081483  0.1443853 

There are lots of arguments in cvts() and hybridModel() that allow you to control exactly which forecast period is used and other tweaking.

chaojieji commented 7 years ago

I have gotten your idea. Appreciate for your support and instruction.