简体   繁体   English

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

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

I have a hierarchical time series, the bottom level series of which all exhibit intermittent demand. 我有一个分层的时间序列,其中底层系列都表现出间歇性的需求。 It seems advantageous to use Hyndman's HTS package for optimal combination within the hierarchy. 使用Hyndman的HTS软件包在层次结构中实现最佳组合似乎是有利的。 It also seems advantageous to use Kourentzes' MAPA package for multiple aggregation prediction of the intermittent demand. 使用Kourentzes的MAPA包进行间歇性需求的多重聚合预测似乎也是有利的。 In essence, I want to do something like: 从本质上讲,我想做的事情如下:

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

However, it is unclear to me if / how I can combine the two, since forecast.gts() only accepts fmethod=c("ets", "arima", "rw"). 但是,我不清楚我是否/如何将两者结合起来,因为forecast.gts()只接受fmethod=c("ets", "arima", "rw").

Is there a clever way to pass different forecasting methods to forecast.gts() without having to tear up the code? 是否有一种聪明的方法可以将不同的预测方法传递给forecast.gts()而不必撕掉代码?

Example to clarify what I mean: 举例澄清我的意思:

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 <- ?

I'm posting because after a closer look at the hts documentation (insert well-deserved RTFM here), I think I found a work-around using the combinef() function from hts, which can be used to optimally combine forecasts outside of the forecast.gts() environment. 我发帖是因为仔细看了一下hts文档(在这里插入了当之无愧的RTFM)后,我想我找到了一个使用hts的combinef()函数的解决方法,可以用来最优地组合hts以外的预测。 forecast.gts()环境。 I'll leave it up for a while before accepting as an answer so others can tell me if I'm wrong. 在接受答案之前,我会暂时搁置一段时间,以便其他人可以告诉我,如果我错了。

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

"Is there a clever way to pass different forecasting methods to forecast.gts() without having to tear up the code?" “有没有一种聪明的方法可以将不同的预测方法传递给forecast.gts()而不必撕掉代码?” - Almost certainly not. - 几乎肯定不是。 forecast.gts() does not allow you to plug in forecast methods along the lines of the family parameter to glm() and similar. forecast.gts()不允许您沿着family参数的行插入预测方法到glm()和类似的方法。

It will likely be easiest to run the MAPA forecasts and then reimplement the optimal combination yourself. 最简单的方法是运行MAPA预测,然后自己重​​新实现最佳组合。 It's really not all that hard, I did it myself a few times before the hts package came along. 这真的不是那么难,我在hts包出现之前自己做了几次。 Look at the references in the hts package; 查看hts包中的引用; most of them are available as preprints on Rob Hyndman's website. 其中大部分都可以作为Rob Hyndman网站上的预印本。

One key problem in combining the optimal combination approach with intermittent demand forecasts is that the optimal combination may well yield negative forecasts. 将最优组合方法与间歇性需求预测相结合的一个关键问题是最优组合可能会产生负面预测。 These may be "optimal" in the GLS sense used here, but they make no sense for demands. 这些在这里使用的GLS意义上可能是“最佳的”,但它们对需求毫无意义。 My solution was to use pcls() in the mgcv package for the actual reconciliation, in order to constrain the solution (ie, the bottom level reconciled forecasts) to be nonnegative. 我的解决方案是使用pcls()mgcv包的实际和解,以便约束解决方案(即底层不甘心预测)是负数。

I have run successfully in the past small experiments using MAPA forecasts and combinef. 我在过去使用MAPA预测和combinef的小型实验中成功运行。 Stephan's point about the negative forecasts remains an issue. 斯蒂芬关于负面预测的观点仍然存在问题。 You might be interested to look into iMAPA in the tsintermittent package that is specifically designed to produce forecasts for intermittent demand time series. 您可能有兴趣在tsintermittent包中查看iMAPA,该包专门用于生成间歇性需求时间序列的预测。 In contrast to MAPA that one implements Croston's method, SBA and exponential smoothing to choose from in the various temporal aggregation levels. 与MAPA相比,人们实现了Croston方法,SBA和指数平滑以在各种时间聚合级别中进行选择。

I would be very interested in learning more about your results. 我非常有兴趣了解您的结果。 Perhaps a relevant research was presented in last year's ISF by E. Spiliotis et al. 也许E. Spiliotis等人在去年的ISF中提出了相关研究。 Examining the effect of temporal aggregation on forecasting accuracy for hierarchical energy consumption time series . 检验时间聚合对分层能耗时间序列预测精度的影响

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

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