Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

r - fable box_cox accuracy error and forecast not converting back to original series

I'm following on a previous answer related with fable R and the use of box_cox function to transform the response variable. When I tried to get the accuracy of model an error occurred. Also when I used the forecast function the series is still transformed. Thanks

Library(fpp3)

lambda2 <- tsibbledata::PBS %>%
  aggregate_key(Concession, Cost = sum(Cost)) %>%
  features(Cost, features = guerrero)

lambda2

#> # A tibble: 3 x 2
#>   Concession   lambda_guerrero
#>   <chr*>                 <dbl>
#> 1 Concessional           0.252
#> 2 General                0.658
#> 3 <aggregated>           0.364

tsibbledata::PBS %>%
  aggregate_key(Concession, Cost = sum(Cost)) %>%
  # Add lambda to the dataset, matching based on the key variable
  left_join(lambda2, by = "Concession") %>% 
  autoplot(box_cox(Cost, lambda_guerrero))

tsibbledata::PBS %>%
  aggregate_key(Concession, Cost = sum(Cost)) %>%
  # Add lambda to the dataset, matching based on the key variable
  left_join(lambda2, by = "Concession") %>% 
  autoplot(box_cox(Cost, lambda_guerrero)) + 
  facet_grid(rows = vars(Concession), scales = "free_y")

act<-tsibbledata::PBS %>%
  aggregate_key(Concession, Cost = sum(Cost),Scripts=sum(Scripts))

fut<-new_data(act, 10) %>% mutate(Scripts=mean(act$Scripts))

fit<-act %>% 
  # Add lambda to the dataset, matching based on the key variable
  left_join(lambda2, by = "Concession") %>% 
  model( arima=ARIMA(box_cox(Cost,lambda_guerrero)~Scripts))


accuracy(fit)

#> Error: Problem with `mutate()` input `fit`.
#> x Can't convert a call to a string
#> i Input `fit` is `map(fit, accuracy, measures = measures, ...)`.

fit %>% forecast(fut ) 

#> A fable: 30 x 6 [1M]
#> Key:     Concession, .model [3]
#> Concession   .model    Month `box_cox(Cost, lambda_guerrero)` .mean  Scripts
#> <chr>        <chr>     <mth>                           <dist> <dbl>    <dbl>
#>   1 Concessional arima  2008 Jul                      N(521, 2.3)  521. 7752813.
#> 2 Concessional arima  2008 Aug                      N(521, 3.8)  521. 7752813.
#> 3 Concessional arima  2008 Sep                      N(522, 4.8)  522. 7752813.
#> 4 Concessional arima  2008 Oct                      N(525, 5.8)  525. 7752813.
#> 5 Concessional arima  2008 Nov                      N(528, 6.8)  528. 7752813.
#> 6 Concessional arima  2008 Dec                      N(530, 7.7)  530. 7752813.
#> 7 Concessional arima  2009 Jan                      N(530, 8.7)  530. 7752813.
#> 8 Concessional arima  2009 Feb                      N(524, 9.5)  524. 7752813.
#> 9 Concessional arima  2009 Mar                       N(525, 10)  525. 7752813.
#> 10 Concessional arima  2009 Apr                       N(524, 11)  524. 7752813.
#> ... with 20 more rows
question from:https://stackoverflow.com/questions/65852153/fable-box-cox-accuracy-error-and-forecast-not-converting-back-to-original-series

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...