| split_index | R Documentation |
Create train and test indices for time series cross-validation.
split_index(
n_total,
n_init,
n_ahead,
n_skip = 0,
n_lag = 0,
mode = "slide",
exceed = FALSE
)
n_total |
Integer. The total number of observations in the time series. |
n_init |
Integer. The number of observations in the initial training window. |
n_ahead |
Integer. The forecast horizon, i.e. the number of observations in each test window. |
n_skip |
Integer. The number of observations to skip between split
origins. The default is |
n_lag |
Integer. The number of lagged observations to include before the
test window. The default is |
mode |
Character value. Either |
exceed |
Logical value. If |
split_index() creates integer index vectors for rolling-origin
resampling. The function can create either fixed-window or expanding-window
splits:
mode = "slide" creates a fixed training window that moves
forward over time.
mode = "stretch" creates an expanding training window that
always starts at the first observation.
The first training window contains n_init observations. Each test
window contains n_ahead observations. The argument n_skip
controls how many observations are skipped between consecutive split origins.
For example, with n_ahead = 18 and n_skip = 17, consecutive
test windows are non-overlapping.
If n_lag > 0, the test indices include lagged observations before the
forecast horizon. This is useful when lagged predictors are needed for
constructing features during testing.
If exceed = TRUE, additional out-of-sample test indices are allowed to
exceed the original sample size.
A list with two elements:
train: a list of integer vectors with training indices.
test: a list of integer vectors with test indices.
Other time series cross-validation:
make_future(),
make_split(),
make_tsibble(),
slice_test(),
slice_train()
# Fixed-window splits
fixed_index <- split_index(
n_total = 180,
n_init = 120,
n_ahead = 18,
n_skip = 17,
n_lag = 0,
mode = "slide",
exceed = FALSE
)
fixed_index
# Expanding-window splits
expanding_index <- split_index(
n_total = 180,
n_init = 120,
n_ahead = 18,
n_skip = 17,
n_lag = 0,
mode = "stretch",
exceed = FALSE
)
expanding_index
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.