Walks a tidymodels workflow() or caret::train() object and
validates every step — preprocessing, feature selection, tuning, and
model fitting — for information leakage.
Arguments
- pipeline
A modeling pipeline object. Supported types:
A tidymodels
workflowobject (fitted or unfitted)A
caret::trainobjectA list with named components (recipe, model, tune_results, etc.)
- train_idx
Integer vector of training row indices.
- test_idx
Integer vector of test row indices.
- data
Optional data frame. Required for parameter-level checks.
- ...
Additional arguments passed to inspectors.
Value
An object of class "borg_pipeline" containing:
- stages
Named list of per-stage BorgRisk results
- overall
Aggregated BorgRisk for the full pipeline
- n_stages
Number of stages inspected
- leaking_stages
Character vector of stage names with hard violations
Details
borg_pipeline() decomposes a pipeline into stages and inspects each:
Preprocessing: Recipe steps, preProcess, PCA, scaling
Feature selection: Variable importance, filtering
Hyperparameter tuning: Inner CV resamples
Model fitting: Training data scope, row counts
Post-processing: Threshold optimization, calibration
Each stage gets its own BorgRisk assessment. The overall result aggregates all risks across stages.
Examples
# \donttest{
if (requireNamespace("caret", quietly = TRUE)) {
ctrl <- caret::trainControl(method = "cv", number = 5)
model <- caret::train(mpg ~ ., data = mtcars[1:25, ], method = "lm",
trControl = ctrl, preProcess = c("center", "scale"))
result <- borg_pipeline(model, train_idx = 1:25, test_idx = 26:32,
data = mtcars)
print(result)
}
# }