rforecastfable-r

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. 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. 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)

Solution

  • This error is coming from the forecast::accuracy.default() method. To evaluate test-set forecast accuracy you would use the accuracy() function with a <fable> object.

    Something like this should work:

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