| build_cv_folds | R Documentation |
Builds up to k_requested chronological, non-overlapping walk-forward
folds from one ds-ordered series. Each fold's test window is exactly
horizon_periods rows long. Degrades gracefully: if the series can't
support k_requested folds, fewer are returned instead of erroring –
possibly zero, for a very short series.
build_cv_folds(
df,
horizon_periods,
k_requested,
min_train = 2,
window = c("expanding", "rolling"),
train_window = NULL
)
df |
A data frame with a |
horizon_periods |
Integer, the length of each fold's test window,
in the same units as |
k_requested |
Integer, the number of folds requested (may return fewer). |
min_train |
Integer, the minimum number of training rows a fold
must have to be included. Default |
window |
|
train_window |
Integer, the fixed training-window width used when
|
A list of folds, oldest-first (fold 1 has the smallest training
window under "expanding", or the same fixed width under
"rolling"), each a list with train and test data frames.
df <- data.frame(ds = as.Date("2024-01-01") + 0:29, y = 1:30)
folds <- build_cv_folds(df, horizon_periods = 5, k_requested = 3)
length(folds)
rolling_folds <- build_cv_folds(df, horizon_periods = 5, k_requested = 3,
window = "rolling", train_window = 10)
length(rolling_folds)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.