简体   繁体   English

R fabletools accuracy() 第一个参数应该是预测对象或时间序列

[英]R fabletools accuracy() first argument should be a forecast object or a time series

I'm trying to pull diagnostics for 3 models at once using the accuracy() function from fabletools.我正在尝试使用 fabletools 中的 accuracy() 函数一次提取 3 个模型的诊断。 I get this error:我收到此错误:

Error in accuracy.default(rec_fore, df) : 
  First argument should be a forecast object or a time series.

rec_fore is a tbl_ts. rec_fore 是一个 tbl_ts。 From the online documentation, I believe this function should work on this class without needing to be coerced.从在线文档中,我相信这个函数应该在这个类上工作,而不需要被强制。 Any tips?有小费吗? Code below..下面的代码..

# Train

rec_fit <- df_train %>%
        model(
          nnar_rec = NNETAR(rec, lambda = "auto"),
          arima_rec = ARIMA(rec, stepwise = FALSE, approx = FALSE),
          prophet_rec = prophet(rec ~ season(type = "multiplicative"))
          )

# Forecast

rec_fore <- rec_fit %>%
              forecast(h = 29) %>%
              hilo(level = c(95)) %>%
              unpack_hilo("95%")

# Diagnose

fabletools::accuracy(rec_fore, df)

This error is coming from the forecast::accuracy.default() method.此错误来自forecast::accuracy.default()方法。 To evaluate test-set forecast accuracy you would use the accuracy() function with a <fable> object.要评估测试集的预测准确性,您可以使用带有<fable>对象的accuracy()函数。

Something like this should work:像这样的东西应该工作:

rec_fit %>%
  forecast(h = 29) %>%
  accuracy(df)

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

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