在 forecast.gts 中添加 thief 和 mlp.thief 预测函数(即 fmethod = c("ets", "arima", "rw", "thief", "mlp.thief", "elm.thief"))?
Adding thief and mlp.thief forecasting functions in forecast.gts (i.e. fmethod = c("ets", "arima", "rw", "thief", "mlp.thief", "elm.thief"))?
我有分层数据。数据具有以下级别(从上到下):
- 生产设施
- 行业
- 客户
- 产品组
- SKU
我正在使用 r
库 hts
进行预测。为了提高准确性,我想使用 thief
库(还有 nnfor::mlp.thief
和 nnfor::elm.thief
函数)。我通过以下方式将这些功能添加到 forecast.hts()
,
loopfn <- function(x, ...) {
out <- list()
if (is.null(FUN)) {
if (fmethod == "ets") {
models <- forecast::ets(x, lambda = lambda, ...)
out$pfcasts <- forecast::forecast(models, h = h, PI = FALSE)$mean
} else if (fmethod == "arima") {
models <- forecast::auto.arima(x, lambda = lambda, xreg = xreg,
parallel = FALSE, ...)
out$pfcasts <- forecast::forecast(models, h = h, xreg = newxreg)$mean
} else if (fmethod == "rw") {
models <- forecast::rwf(x, h = h, lambda = lambda, ...)
out$pfcasts <- models$mean
} else if (fmethod == "thief"){
models <- thief::thief(x, h = h , usemodel = usemodel, ...)
out$pfcasts <- models$mean
}else if (fmethod == "mlp.thief"){
models <- nnfor::mlp.thief(x, h = h , ...)
out$pfcasts <- models$mean
} else if (fmethod == "elm.thief"){
models <- nnfor::elm.thief(x, h = h , ...)
out$pfcasts <- models$mean
}
} else { # user defined function to produce point forecasts
models <- FUN(x, ...)
if (is.null(newxreg)) {
out$pfcasts <- forecast(models, h = h)$mean
} else {
out$pfcasts <- forecast(models, h = h, xreg = newxreg)$mean
}
}
if (keep.fitted) {
out$fitted <- stats::fitted(models)
}
if (keep.resid) {
out$resid <- stats::residuals(models)
}
return(out)
}
这样做理论上会有什么问题吗?事实上,它提高了预测的准确性。
考虑到以下文献,我没有发现任何问题 Hyndman et.al. 2017 and Hyndman et.al. 2011
我可以使用带有参数 FUN =
的任何函数
该函数必须是预测对象。
我在 Covid-19 之前使用了一种类似的方法来预测巴西的财政收入(但我使用的是 nnetar
理论上是 MLP 的函数)
分层预测完全独立于您使用的模型。
您甚至可以使用判断性预测(但在这种情况下,您必须使用 nseries
调节)
所以使用“elm.thief”没问题。
我有分层数据。数据具有以下级别(从上到下):
- 生产设施
- 行业
- 客户
- 产品组
- SKU
我正在使用 r
库 hts
进行预测。为了提高准确性,我想使用 thief
库(还有 nnfor::mlp.thief
和 nnfor::elm.thief
函数)。我通过以下方式将这些功能添加到 forecast.hts()
,
loopfn <- function(x, ...) {
out <- list()
if (is.null(FUN)) {
if (fmethod == "ets") {
models <- forecast::ets(x, lambda = lambda, ...)
out$pfcasts <- forecast::forecast(models, h = h, PI = FALSE)$mean
} else if (fmethod == "arima") {
models <- forecast::auto.arima(x, lambda = lambda, xreg = xreg,
parallel = FALSE, ...)
out$pfcasts <- forecast::forecast(models, h = h, xreg = newxreg)$mean
} else if (fmethod == "rw") {
models <- forecast::rwf(x, h = h, lambda = lambda, ...)
out$pfcasts <- models$mean
} else if (fmethod == "thief"){
models <- thief::thief(x, h = h , usemodel = usemodel, ...)
out$pfcasts <- models$mean
}else if (fmethod == "mlp.thief"){
models <- nnfor::mlp.thief(x, h = h , ...)
out$pfcasts <- models$mean
} else if (fmethod == "elm.thief"){
models <- nnfor::elm.thief(x, h = h , ...)
out$pfcasts <- models$mean
}
} else { # user defined function to produce point forecasts
models <- FUN(x, ...)
if (is.null(newxreg)) {
out$pfcasts <- forecast(models, h = h)$mean
} else {
out$pfcasts <- forecast(models, h = h, xreg = newxreg)$mean
}
}
if (keep.fitted) {
out$fitted <- stats::fitted(models)
}
if (keep.resid) {
out$resid <- stats::residuals(models)
}
return(out)
}
这样做理论上会有什么问题吗?事实上,它提高了预测的准确性。
考虑到以下文献,我没有发现任何问题 Hyndman et.al. 2017 and Hyndman et.al. 2011
我可以使用带有参数 FUN =
的任何函数
该函数必须是预测对象。
我在 Covid-19 之前使用了一种类似的方法来预测巴西的财政收入(但我使用的是 nnetar
理论上是 MLP 的函数)
分层预测完全独立于您使用的模型。
您甚至可以使用判断性预测(但在这种情况下,您必须使用 nseries
调节)
所以使用“elm.thief”没问题。