I have a monthly time series data and I want to model it using different models in the Fable package by using cross validation to know the best model among the models considered.
# My data
google <- read_csv("google.csv") %>%
tsibble(index = date)
# dimension of the data is 60 by 2.
]1
# Training data for cross validation
google_tr <- google %>%
slice(1:(n()-1)) %>%
stretch_tsibble(.init = 3, .step = 1)
# Building models for the data
fc <- google_tr %>%
model(ets = ETS(closing_price),
arima = ARIMA(closing_price),
rw = RW(closing_price ~ drift()),
prophet = prophet(closing_price)) %>%
forecast(h = "1 year")
A lot of warnings appeared!
Model evaluation
fc %>% accuracy(google)
I have read https://otexts.com/fpp3/tscv.html and https://otexts.com/fpp3/arima-ets.html#example-comparing-arima-and-ets-on-non-seasonal-data time without number and I still don't know how to select the right training data. If I can get the right input for slice()
and stretch_tsibble()
for monthly data in the chunk below, the problem would be solved.
google_tr <- google %>%
slice(1:(n()-1)) %>%
stretch_tsibble(.init = 3, .step = 1)