混合预测 - 单模型预测的平均值 - 通常用于产生比任何预测模型更好的点估计。我展示了如何为混合预测构建预测区间,这种预测的覆盖范围比最常用的预测区间更准确(即80%的实际观测结果确实在80%置信区间内)。
预测间隔
预报员的问题是在预测组合中使用的预测间隔。预测间隔是与置信区间相似但不相同的概念。预测间隔是对尚未知但将在未来的某个点观察到的值(或更确切地说,可能值的范围)的估计。而置信区间是对基本上不可观察的参数的可能值范围的估计。预测间隔需要考虑模型中的不确定性,模型中参数的不确定估计(即那些参数的置信区间),以及与预测的特定点相关联的个体随机性。
介绍hybridf()
我喜欢结合auto.arima()并ets(),有效地进行混合预测。为了使更方便,我创建了一个hybridf()在R中为我做这个并生成类对象的函数forecast。
library(devtools) install_github("robjhyndman/forecast") # development version needed sorry library(forecast)
need-to-insert-img
need-to-insert-img
深灰色区域是80%预测区间,浅灰色区域是95%预测区间。
测试M3
结果如下:
变量准确度
ets_p800.75
ets_p950.90
auto.arima_p800.74
auto.arima_p950.88
hybrid_p800.83
hybrid_p950.94
我的混合方法有在接近广告的成功率,而这两个预测区间ets()和auto.arima()不太成功。
以下是我在M3数据上测试的方法。我构建了一个小函数pi_accuracy()来帮助,它利用了类预测对象返回一个名为“lower”的矩阵和另一个名为“upper”的矩阵,每个预测区间级别都有一列。
<- function(fc, yobs){\n # checks the success of prediction intervals of an object of class \n \n In <- (yobsm \n }","classes":{"has":1},"lang":""}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet">#------------------setup------------------------ library(forecast) ly = "myfont")) pi_accuracy <- function(fc, yobs){ # checks the success of prediction intervals of an object of class In <- (yobsm }
need-to-insert-img
实际上拟合所有预测相对简单。我的笔记本电脑花了大约一个小时。
<- length(M3) # ie 3003\nresults <- matrix(0, nrow = num_series, ncol = 7)\n\nfor(i in 1:num_series){\n cat(i, \" \") # let me know how it's going as it loops through...\n series <- M3[[i]]\n ccess\n \n fc1 <- fc3$fc_ets\n r \n geom_smooth(se = FALSE, method = \"lm\") +\n theme(panel.grid.minor = element_blank())","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet">#============forecasting with default values=============== num_series <- length(M3) # ie 3003 results <- matrix(0, nrow = num_series, ncol = 7) for(i in 1:num_series){ cat(i, " ") # let me know how it's going as it loops through... series <- M3[[i]] ccess fc1 <- fc3$fc_ets r geom_smooth(se = FALSE, method = "lm") + theme(panel.grid.minor = element_blank())
need-to-insert-img
need-to-insert-img
预测
变量准确度
ets_p800.72
ets_p950.88
auto.arima_p800.70
auto.arima_p950.86
hybrid_p800.80
hybrid_p950.92
<- length(M3)\nresultsb <- matrix(0, nrow = num_series, ncol = 7)\n\nfor(i in 1:num_series){\n cat(i, \" \")\n \n gather(variable, value, -h) %>%\n mutate(weighted_val ighted_value) / sum(h), 2))","classes":{"has":1},"lang":""}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet">#=====with bootstrapping instead of formulae for the prediction intervals============= num_series <- length(M3) resultsb <- matrix(0, nrow = num_series, ncol = 7) for(i in 1:num_series){ cat(i, " ") gather(variable, value, -h) %>% mutate(weighted_val ighted_value) / sum(h), 2))
need-to-insert-img
结论
根据M3竞赛数据进行测试hybridf(),通过组合ets()并auto.arima()形成的预测到期望的水平,即80%预测interval在80%的时间内包含真值,95%的预测间隔包含不到95%的时间的真值。
网友评论