MASE requires the training data in order to compute the scaling factor in the denominator. If you don't pass that data to accuracy()
, then it cannot compute the MASE. In your code, you pass the test data only. So just replace that with all the data (training and test data) and the accuracy()
function will be able to do all the required calculations.
library("fpp3")
#> ββ Attaching packages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ fpp3 0.1 ββ
#> β tibble 2.1.3 β tsibble 0.8.6
#> β dplyr 0.8.4 β tsibbledata 0.1.0.9000
#> β tidyr 1.0.2 β feasts 0.1.2.9000
#> β lubridate 1.7.4 β fable 0.1.2.9000
#> β ggplot2 3.3.0.9000
#> ββ Conflicts ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ fpp3_conflicts ββ
#> x lubridate::date() masks base::date()
#> x dplyr::filter() masks stats::filter()
#> x tsibble::id() masks dplyr::id()
#> x tsibble::interval() masks lubridate::interval()
#> x dplyr::lag() masks stats::lag()
#> x tsibble::new_interval() masks lubridate::new_interval()
google_stock <- gafa_stock %>%
filter(Symbol == "GOOG") %>%
mutate(day = row_number()) %>%
update_tsibble(index = day, regular = TRUE)
google_2015 <- google_stock %>% filter(year(Date) == 2015)
google_jan_2016 <- google_stock %>%
filter(yearmonth(Date) == yearmonth("2016 Jan"))
google_fit <- google_2015 %>%
model(
Mean = MEAN(Close),
`NaΓ―ve` = NAIVE(Close),
Drift = RW(Close ~ drift())
)
google_fc <- google_fit %>%
forecast(google_jan_2016)
accuracy(google_fc, google_stock)
#> # A tibble: 3 x 10
#> .model Symbol .type ME RMSE MAE MPE MAPE MASE ACF1
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Drift GOOG Test -49.8 53.1 49.8 -6.99 6.99 7.84 0.604
#> 2 Mean GOOG Test 117. 118. 117. 16.2 16.2 18.4 0.496
#> 3 NaΓ―ve GOOG Test -40.4 43.4 40.4 -5.67 5.67 6.36 0.496
Created on 2020-02-09 by the reprex package (v0.3.0)