error in accuracy() from library(fpp3)

Subject: Issue with accuracy() function from fpp3 package
Message:
Hello,

I'm encountering an issue with the accuracy() function from the fpp3 package. My forecast object is of class fbl_ts, but when I try to use accuracy(tslm_forecast, data), I get an error saying "No accuracy method found for an object of class fbl_ts." I have confirmed that my package version is up to date (version 0.5).

Can someone please help me troubleshoot this issue? Is there something I might be missing or any known workarounds for this problem?

Thank you for your assistance!

code:

library(fpp3)
recent_production <- aus_production |>
  filter(year(Quarter) >= 1992)
beer_train <- recent_production |>
  filter(year(Quarter) <= 2007)

beer_fit <- beer_train |>
  model(
    Mean = MEAN(Beer),
    `Naïve` = NAIVE(Beer),
    `Seasonal naïve` = SNAIVE(Beer),
    Drift = RW(Beer ~ drift())
  )

beer_fc <- beer_fit |>
  forecast(h = 10)

beer_fc |>
  autoplot(
    aus_production |> filter(year(Quarter) >= 1992),
    level = NULL
  ) +
  labs(
    y = "Megalitres",
    title = "Forecasts for quarterly beer production"
  ) +
  guides(colour = guide_legend(title = "Forecast"))

accuracy(beer_fc, recent_production)

accuracy(beer_fc, recent_production)
error message: Error in accuracy.default(beer_fc, recent_production) :
No accuracy method found for an object of class fbl_tsNo accuracy method found for an object of class tbl_tsNo accuracy method found for an object of class tbl_dfNo accuracy method found for an object of class tblNo accuracy method found for an object of class data.frame


Referred here by Forecasting: Principles and Practice, by Rob J Hyndman and George Athanasopoulos

Hi, not sure, but it ran for me:

> accuracy(beer_fc, recent_production)
# A tibble: 4 x 10
  .model         .type    ME  RMSE   MAE    MPE  MAPE  MASE RMSSE    ACF1
  <chr>          <chr> <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>   <dbl>
1 Drift          Test  -54.0  64.9  58.9 -13.6  14.6  4.12  3.87  -0.0741
2 Mean           Test  -13.8  38.4  34.8  -3.97  8.28 2.44  2.29  -0.0691
3 Naïve          Test  -51.4  62.7  57.4 -13.0  14.2  4.01  3.74  -0.0691
4 Seasonal naïve Test    5.2  14.3  13.4   1.15  3.17 0.937 0.853  0.132 

What version of the packages have you got running?

EDIT - You have noted that yours is up to date.

running the latest package version 0.5, it give error, before that, i was using version 0.4, it gives the same error as well.

sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C LC_TIME=English_United States.utf8

time zone: Asia/Kuala_Lumpur
tzcode source: internal

attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base

other attached packages:
[1] rugarch_1.4-9 forecast_8.21 zoo_1.8-12 e1071_1.7-13 glmnet_4.1-7 Matrix_1.5-4.1 readxl_1.4.3
[8] fable_0.3.3 feasts_0.3.1 fabletools_0.3.3 tsibbledata_0.4.1 tsibble_1.1.3 ggplot2_3.4.2 lubridate_1.9.2
[15] tidyr_1.3.0 dplyr_1.1.2 tibble_3.2.1 fpp3_0.5

loaded via a namespace (and not attached):
[1] tidyselect_1.2.0 timeDate_4022.108 farver_2.1.1 latex2exp_0.9.6 pracma_2.4.2
[6] GeneralizedHyperbolic_0.8-4 digest_0.6.33 timechange_0.2.0 lifecycle_1.0.3 ellipsis_0.3.2
[11] survival_3.5-5 Rsolnp_1.16 magrittr_2.0.3 compiler_4.3.1 rlang_1.1.1
[16] tools_4.3.1 utf8_1.2.3 knitr_1.43 labeling_0.4.2 mclust_6.0.0
[21] curl_5.0.1 TTR_0.24.3 KernSmooth_2.23-21 withr_2.5.0 purrr_1.0.1
[26] numDeriv_2016.8-1.1 nnet_7.3-19 grid_4.3.1 fansi_1.0.4 xts_0.13.1
[31] colorspace_2.1-0 progressr_0.13.0 scales_1.2.1 iterators_1.0.14 MASS_7.3-60
[36] cli_3.6.1 mvtnorm_1.2-2 anytime_0.3.9 crayon_1.5.2 generics_0.1.3
[41] rstudioapi_0.15.0 proxy_0.4-27 stringr_1.5.0 splines_4.3.1 urca_1.3-3
[46] cellranger_1.1.0 vctrs_0.6.3 spd_2.0-1 tseries_0.10-54 foreach_1.5.2
[51] quantmod_0.4.24 glue_1.6.2 SkewHyperbolic_0.4-0 codetools_0.2-19 DistributionUtils_0.6-0
[56] distributional_0.3.2 stringi_1.7.12 shape_1.4.6 gtable_0.3.3 quadprog_1.5-8
[61] lmtest_0.9-40 munsell_0.5.0 pillar_1.9.0 rappdirs_0.3.3 truncnorm_1.0-9
[66] R6_2.5.1 ks_1.14.0 evaluate_0.21 lattice_0.21-8 fracdiff_1.5-2
[71] class_7.3-22 Rcpp_1.0.11 nlme_3.1-162 xfun_0.39 pkgconfig_2.0.3

The issue here is that you are loading the forecast package, which you do not need. It uses the generics::accuracy() function, while the version of fabletools you are using has its own accuracy generic. The problem won't occur after the next update to fabletools when it will use the same generic as the forecast package. In the meantime, either don't load the forecast package, or explictly use fabletools::accuracy().

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.