# Inspect a preprocessing object
data(mtcars)
train_idx <- 1:25
test_idx <- 26:32
# BAD: preProcess fitted on full data (will detect leak)
pp_bad <- scale(mtcars[, -1])
# GOOD: preProcess fitted on train only
pp_good <- scale(mtcars[train_idx, -1])
Run the code above in your browser using DataLab