rstudio-conf-2020 / time-series-forecasting

Creative Commons Attribution Share Alike 4.0 International
222 stars 131 forks source link

Unnest of fable failed #7

Closed hermandr closed 4 years ago

hermandr commented 4 years ago

Hi,

I tried to knit the rmd from the materials folder. I encountered an error in "6-fable.Rmd" file on line 352. To reproduce the error the reprex is below.

What concerns me is unnest() of a fable does not work anymore. I tried to unnest the columns and it also failed.

library(tidyverse)
library(fpp3)
#> -- Attaching packages ----------------------------------------------------- fpp3 0.3 --
#> v lubridate   1.7.9     v feasts      0.1.4
#> v tsibble     0.9.2     v fable       0.2.1
#> v tsibbledata 0.2.0
#> -- Conflicts -------------------------------------------------------- fpp3_conflicts --
#> x lubridate::date()   masks base::date()
#> x dplyr::filter()     masks stats::filter()
#> x tsibble::interval() masks lubridate::interval()
#> x dplyr::lag()        masks stats::lag()

brick_fit <-  aus_production %>%
  filter(!is.na(Bricks)) %>%
  model(
    `Seasonal_naive` = SNAIVE(Bricks),
    `Naive` = NAIVE(Bricks),
    Drift = RW(Bricks ~ drift()),
    Mean = MEAN(Bricks)
  )

brick_fit
#> # A mable: 1 x 4
#>   Seasonal_naive   Naive         Drift    Mean
#>          <model> <model>       <model> <model>
#> 1       <SNAIVE> <NAIVE> <RW w/ drift>  <MEAN>

brick_fc <- brick_fit %>%
  forecast(h = "5 years")

print(brick_fc, n = 4)
#> # A fable: 80 x 4 [1Q]
#> # Key:     .model [4]
#>   .model         Quarter       Bricks .mean
#>   <chr>            <qtr>       <dist> <dbl>
#> 1 Seasonal_naive 2005 Q3 N(428, 2336)   428
#> 2 Seasonal_naive 2005 Q4 N(397, 2336)   397
#> 3 Seasonal_naive 2006 Q1 N(355, 2336)   355
#> 4 Seasonal_naive 2006 Q2 N(435, 2336)   435
#> # ... with 76 more rows

brick_fc %>% hilo(level=c(50,75)) %>% unnest()
#> Warning: `cols` is now required when using unnest().
#> Please use `cols = c(Bricks, `50%`, `75%`)`
#> Error: Input must be list of vectors

Created on 2020-08-25 by the reprex package (v0.3.0)

Herman

mitchelloharawild commented 4 years ago

Hi Herman,

Using unnest() to unpack <hilo> objects had to be removed when we added support for vctrs and dplyr v1.0.0 in fabletools v0.2.0. Unfortunately we couldn't give an informative error here, because unnest() is from tidyr.

The unpack_hilo() function continues to work, and you can now also access the elements of a <hilo> using $. For example, my_interval$lower will give you the lower bound.

More details on the changes can be found here: https://fabletools.tidyverts.org/news/index.html

I will update the slides to reflect these changes.

Best, Mitch.

hermandr commented 4 years ago

Thank you for the response. I can run the code and understand it now.

Herman