tidyverts / fable

Tidy time series forecasting
https://fable.tidyverts.org
GNU General Public License v3.0
564 stars 66 forks source link

Could not find respnose variables - Error when using accuracy() #273

Closed Vidaringa closed 4 years ago

Vidaringa commented 4 years ago

Hi,

I've been using the package but suddenly I get an error when using the accuracy() function. I'm following this example: https://robjhyndman.com/hyndsight/fable/

Here is the code:

library(tidyverse)
library(tsibble)
library(lubridate)
library(fable)

tourism <- tourism %>%
    mutate(
        State = recode(State,
                       "Australian Capital Territory" = "ACT",
                       "New South Wales" = "NSW",
                       "Northern Territory" = "NT",
                       "Queensland" = "QLD",
                       "South Australia" = "SA",
                       "Tasmania" = "TAS",
                       "Victoria" = "VIC",
                       "Western Australia" = "WA"
        )
    )

train <- tourism %>%
    filter(year(Quarter) <= 2014)

fit <- train %>%
    model(
        ets = ETS(Trips),
        arima = ARIMA(Trips),
        snaive = SNAIVE(Trips)
    ) %>%
    mutate(mixed = (ets + arima + snaive) / 3)

fc <- fit %>% forecast(h = "3 years")

accuracy(fc, tourism)

Which gives the error: Error: Could not find response variable(s) in the fable: Trips

mitchelloharawild commented 4 years ago

I am unable to reproduce this issue with the development versions of the packages. Could you provide your sessionInfo()?

library(tidyverse)
#> Warning: package 'tibble' was built under R version 3.6.3
#> Warning: package 'tidyr' was built under R version 3.6.3
#> Warning: package 'purrr' was built under R version 3.6.3
library(tsibble)
library(lubridate)
#> Warning: package 'lubridate' was built under R version 3.6.3
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:tsibble':
#> 
#>     interval
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
library(fable)
#> Loading required package: fabletools

tourism <- tourism %>%
  mutate(
    State = recode(State,
                   "Australian Capital Territory" = "ACT",
                   "New South Wales" = "NSW",
                   "Northern Territory" = "NT",
                   "Queensland" = "QLD",
                   "South Australia" = "SA",
                   "Tasmania" = "TAS",
                   "Victoria" = "VIC",
                   "Western Australia" = "WA"
    )
  ) %>% 
  filter(Region == "Adelaide")

train <- tourism %>%
  filter(year(Quarter) <= 2014)

fit <- train %>%
  model(
    ets = ETS(Trips),
    arima = ARIMA(Trips),
    snaive = SNAIVE(Trips)
  ) %>%
  mutate(mixed = (ets + arima + snaive) / 3)

fc <- fit %>% forecast(h = "3 years")

accuracy(fc, tourism)
#> # A tibble: 16 x 12
#>    .model Region State Purpose .type      ME  RMSE   MAE     MPE  MAPE  MASE
#>    <chr>  <chr>  <chr> <chr>   <chr>   <dbl> <dbl> <dbl>   <dbl> <dbl> <dbl>
#>  1 arima  Adela… SA    Busine… Test   22.5    28.5  25.3  11.9   14.0  0.765
#>  2 arima  Adela… SA    Holiday Test   21.9    34.8  28.0   9.93  14.8  1.31 
#>  3 arima  Adela… SA    Other   Test    4.71   17.5  14.6   0.529 20.2  1.11 
#>  4 arima  Adela… SA    Visiti… Test   32.8    37.1  32.8  13.7   13.7  1.05 
#>  5 ets    Adela… SA    Busine… Test   24.5    29.4  24.5  13.4   13.4  0.741
#>  6 ets    Adela… SA    Holiday Test   25.3    34.5  29.9  12.4   16.0  1.40 
#>  7 ets    Adela… SA    Other   Test  -12.7    21.0  16.9 -22.5   26.4  1.28 
#>  8 ets    Adela… SA    Visiti… Test   29.6    33.2  29.6  12.5   12.5  0.952
#>  9 mixed  Adela… SA    Busine… Test   19.4    25.4  21.6  10.4   11.9  0.652
#> 10 mixed  Adela… SA    Holiday Test   18.5    31.5  25.3   8.25  13.7  1.19 
#> 11 mixed  Adela… SA    Other   Test   -0.559  17.5  13.8  -6.48  20.3  1.05 
#> 12 mixed  Adela… SA    Visiti… Test   26.4    34.6  27.9  11.1   11.9  0.899
#> 13 snaive Adela… SA    Busine… Test   11.3    20.9  17.2   5.81   9.71 0.519
#> 14 snaive Adela… SA    Holiday Test    8.22   30.5  21.4   2.44  12.4  1.00 
#> 15 snaive Adela… SA    Other   Test    6.33   24.2  17.9   2.56  24.5  1.36 
#> 16 snaive Adela… SA    Visiti… Test   16.9    46.5  38.2   7.22  16.9  1.23 
#> # … with 1 more variable: ACF1 <dbl>

Created on 2020-06-03 by the reprex package (v0.3.0)

Vidaringa commented 4 years ago
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=Icelandic_Iceland.1252  LC_CTYPE=Icelandic_Iceland.1252    LC_MONETARY=Icelandic_Iceland.1252 LC_NUMERIC=C                      
[5] LC_TIME=Icelandic_Iceland.1252    

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

other attached packages:
 [1] fable_0.2.0        fabletools_0.1.3   lubridate_1.7.8    tsibble_0.8.9.9000 forcats_0.5.0      stringr_1.4.0      dplyr_1.0.0       
 [8] purrr_0.3.4        readr_1.3.1        tidyr_1.1.0        tibble_3.0.1       ggplot2_3.3.1      tidyverse_1.3.0   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6     urca_1.3-0       cellranger_1.1.0 pillar_1.4.4     compiler_3.6.3   dbplyr_1.4.4     tools_3.6.3      anytime_0.3.7   
 [9] jsonlite_1.6.1   lifecycle_0.2.0  nlme_3.1-148     gtable_0.3.0     lattice_0.20-38  pkgconfig_2.0.3  rlang_0.4.6      reprex_0.3.0    
[17] cli_2.0.2        DBI_1.1.0        rstudioapi_0.11  haven_2.3.1      withr_2.2.0      xml2_1.3.2       httr_1.4.1       feasts_0.1.3    
[25] fs_1.4.1         generics_0.0.2   vctrs_0.3.0      hms_0.5.3        grid_3.6.3       tidyselect_1.1.0 glue_1.4.1       R6_2.4.1        
[33] fansi_0.4.1      readxl_1.3.1     modelr_0.1.8     blob_1.2.1       magrittr_1.5     backports_1.1.7  scales_1.1.1     ellipsis_0.3.1  
[41] rvest_0.3.5      assertthat_0.2.1 colorspace_1.4-1 stringi_1.4.6    munsell_0.5.0    broom_0.5.6      crayon_1.3.4  
mitchelloharawild commented 4 years ago

The current CRAN version of fable and tsibble are incompatible with the v1.0.0 version of dplyr. If you update to the dev versions of fable (and more importantly fabletools and tsibble), it should work. We are waiting for vctrs to be updated on CRAN to allow us to submit the fixed version of fable/tsibble to CRAN (https://github.com/r-lib/vctrs/issues/1129).

ilebizard commented 4 years ago

Hi Mitchell,

When will there be updates of fable, fabletools, and tsibble to address this issue?

n my applications, in addition to the error: Error: Could not find response variable(s) in the fable, I also have Error in vctrs::vec_rbind(!!!lst_col) : Error in vctrs::vec_rbind(!!!lst_col) : Internal error in vec_proxy_assign_opts(): proxy of type double incompatible with value proxy of type integer.

What is strange is that I can use the command model with a single model (ets, arima, etc) but the moment I use more than one (e.g. model(ets = ETS(y), arima = ARIMA(y)), an error message of vctrs::vec_rbind(!!!lst_col) occurs.

Sorry, my application is for a corporate and I cannot paste it here.

Thanks,

ilebizard commented 4 years ago

Note that I have the error message: Error in vctrs::vec_rbind(!!!lst_col) : Error in vctrs::vec_rbind(!!!lst_col) : Internal error in vec_proxy_assign_opts(): proxy of type double incompatible with value proxy of type integer. after running the command fitModel %>% forecast(h=forecastPeriod), where fitModel is fit using model(model1=..., model2=...)

Thanks,

mitchelloharawild commented 4 years ago

You can install the dev versions of the packages which have already fixed these issues. The hold up is getting the distributional package on CRAN, which you can track here: https://lockedata.github.io/cransays/articles/dashboard.html