Selecting Predictors cross validation method

Hi all,

Speaking about to select predictors with common train / test split, no problem here, could someone give me some example using cross validation, I have checked fpp3 book: 7.5 Selecting predictors | Forecasting: Principles and Practice (3rd ed), speaking about leave one out cross validation, but did not find r examples in my research,

My code use normal train split:

library(fpp3)
library(imputeTS)
library(tidyverse)

serie <- tibble(data = seq(as.Date("1949-01-01"), length = 24, by = "month"),
value1 = sample(1:24),
value2 = sample(1:24)) %>%
as_tsibble() %>%
fill_gaps(.full = TRUE)

serie <- serie %>%
mutate(value1 = na_if(value1, 0.0)) %>%
mutate(value2 = na_if(value2, 0.0)) %>%
na_interpolation()

fit_tslm <- serie %>%
model(TSLM(value1 ~ value2 + lag(value1, 5) + trend() + season("year")))

tslm_change_future <- new_data(serie, 1) %>%
mutate(value2 = mean(serie$value2),
value1 = 6)

fc_tslm <- forecast(fit_tslm, new_data = tslm_change_future)

Best
Lucas

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.