在forecast.gts中添加Theet和mlp.Theet预测函数(即fmethod=c(“ets”)、“arima”、“rw”、“Theet”、“mlp.Theet”、“elm.Theet”)?

在forecast.gts中添加Theet和mlp.Theet预测函数(即fmethod=c(“ets”)、“arima”、“rw”、“Theet”、“mlp.Theet”、“elm.Theet”)?,r,hierarchical-data,forecasting,forecast,R,Hierarchical Data,Forecasting,Forecast,我有一个分层的数据。数据具有以下级别(从上到下): 生产设施 工业 顾客 产品组 SKU 我正在使用r库hts进行预测。为了提高准确性,我想使用thift库(同时使用nnfor::mlp.thift和nnfor::elm.thift函数)。我以以下方式将这些函数添加到forecast.hts() loopfn <- function(x, ...) { out <- list() if (is.null(FUN)) { if (fmethod == "et

我有一个分层的数据。数据具有以下级别(从上到下):

  • 生产设施
  • 工业
  • 顾客
  • 产品组
  • SKU
  • 我正在使用
    r
    hts
    进行预测。为了提高准确性,我想使用
    thift
    库(同时使用
    nnfor::mlp.thift
    nnfor::elm.thift
    函数)。我以以下方式将这些函数添加到
    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)
      }
    

    loopfn我可以使用带有参数
    FUN=

    该函数必须是预测对象

    在新冠肺炎爆发之前,我使用了一种类似的方法来预测巴西的财政收入(但我使用的是
    nnetar
    函数,理论上是一种MLP)

    分层预测完全独立于您使用的模型

    您甚至可以使用判断预测(但在这种情况下,您必须使用
    n系列
    对账)

    所以用“elm.小偷”没问题