繁体   English   中英

将不同的预测方法传递给R中的层次时间序列预测?

[英]Passing different forecasting method to hierarchical time series forecast in R?

我有一个分层的时间序列,其中底层系列都表现出间歇性的需求。 使用Hyndman的HTS软件包在层次结构中实现最佳组合似乎是有利的。 使用Kourentzes的MAPA包进行间歇性需求的多重聚合预测似乎也是有利的。 从本质上讲,我想做的事情如下:

forecast(my_hts, method='comb', fmethod='MAPA')

但是,我不清楚我是否/如何将两者结合起来,因为forecast.gts()只接受fmethod=c("ets", "arima", "rw").

是否有一种聪明的方法可以将不同的预测方法传递给forecast.gts()而不必撕掉代码?

举例澄清我的意思:

library(hts)
library(MAPA)
set.seed(1)

#note intermittent demand of bottom level time series
x <- ts(rpois(365, lambda=0.05), frequency=365, start=2014)
y <- ts(rpois(365, lambda=0.07), frequency=365, start=2014)

#it's easy to make a MAPA forecast for the top-level time series
#but this isn't an optimal hierarchical forecast
mapasimple(x+y)

#it's also easy to make this a HTS and make an optimal hierarchical forecast
#but now I cannot use MAPA
z <- hts(data.frame(x,y)))
z_arima <- forecast(z, fmethod="arima")
z_rw <- forecast(z, fmethod="rw")
z_ets <- forecast(z, fmethod="ets")

#z_MAPA <- ?

我发帖是因为仔细看了一下hts文档(在这里插入了当之无愧的RTFM)后,我想我找到了一个使用hts的combinef()函数的解决方法,可以用来最优地组合hts以外的预测。 forecast.gts()环境。 在接受答案之前,我会暂时搁置一段时间,以便其他人可以告诉我,如果我错了。

fh <- 8

library(hts)
library(MAPA)
set.seed(1)

x <- ts(rpois(365, lambda=0.05), frequency=365, start=2014)
y <- ts(rpois(365, lambda=0.07), frequency=365, start=2014)

my_hts <- hts(data.frame(x,y))

ally <- aggts(my_hts)

allf <- matrix(NA, nrow = fh, ncol = ncol(ally))

for(i in 1:ncol(ally)){
    allf[,i] <- mapafor(ally[,i], 
                        mapaest(ally[,i], outplot=0), 
                        fh = fh, 
                        outplot=0)$outfor
}

allf <- ts(allf)

y.f <- combinef(allf, my_hts$nodes, weights=NULL, keep="bottom")

#here's what the non-reconciled, bottom-level MAPA forecasts look like
print(allf[1,1:2])

 Series 1   Series 2
1 0.1343304 0.06032574

#here's what the reconciled MAPA bottom-level forecasts look like
#notice that they're different
print(y.f[1,])

[1] 0.06030926 0.07402938

“有没有一种聪明的方法可以将不同的预测方法传递给forecast.gts()而不必撕掉代码?” - 几乎肯定不是。 forecast.gts()不允许您沿着family参数的行插入预测方法到glm()和类似的方法。

最简单的方法是运行MAPA预测,然后自己重​​新实现最佳组合。 这真的不是那么难,我在hts包出现之前自己做了几次。 查看hts包中的引用; 其中大部分都可以作为Rob Hyndman网站上的预印本。

将最优组合方法与间歇性需求预测相结合的一个关键问题是最优组合可能会产生负面预测。 这些在这里使用的GLS意义上可能是“最佳的”,但它们对需求毫无意义。 我的解决方案是使用pcls()mgcv包的实际和解,以便约束解决方案(即底层不甘心预测)是负数。

我在过去使用MAPA预测和combinef的小型实验中成功运行。 斯蒂芬关于负面预测的观点仍然存在问题。 您可能有兴趣在tsintermittent包中查看iMAPA,该包专门用于生成间歇性需求时间序列的预测。 与MAPA相比,人们实现了Croston方法,SBA和指数平滑以在各种时间聚合级别中进行选择。

我非常有兴趣了解您的结果。 也许E. Spiliotis等人在去年的ISF中提出了相关研究。 检验时间聚合对分层能耗时间序列预测精度的影响

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM