View source: R/borg_wrappers.R
| borg_vfold_cv | R Documentation |
A guarded version of rsample::vfold_cv() that checks for data
dependencies before creating folds. If spatial, temporal, or clustered
dependencies are detected, random CV is blocked.
borg_vfold_cv(
data,
v = 10,
repeats = 1,
strata = NULL,
coords = NULL,
time = NULL,
groups = NULL,
target = NULL,
allow_override = FALSE,
auto_block = FALSE,
...
)
data |
A data frame. |
v |
Integer. Number of folds. Default: 10. |
repeats |
Integer. Number of repeats. Default: 1. |
strata |
Character. Column name for stratification. |
coords |
Character vector of length 2. Coordinate columns for spatial check. |
time |
Character. Time column for temporal check. |
groups |
Character. Group column for clustered check. |
target |
Character. Target variable for dependency detection. |
allow_override |
Logical. If TRUE, allow random CV with explicit confirmation. Default: FALSE. |
auto_block |
Logical. If TRUE, automatically switch to blocked CV when dependencies detected. If FALSE, throw error. Default: FALSE. |
... |
Additional arguments passed to |
If no dependencies detected or allow_override = TRUE, returns
an rset object from rsample. If dependencies detected and
auto_block = TRUE, returns BORG-generated blocked CV folds.
borg_cv for direct blocked CV generation.
if (requireNamespace("rsample", quietly = TRUE)) {
# Safe: no dependencies
data <- data.frame(x = rnorm(100), y = rnorm(100))
folds <- borg_vfold_cv(data, v = 5)
# Use auto_block to automatically switch to spatial CV:
spatial_data <- data.frame(
lon = runif(100, -10, 10),
lat = runif(100, -10, 10),
response = rnorm(100)
)
folds <- borg_vfold_cv(spatial_data, coords = c("lon", "lat"),
target = "response", auto_block = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.