7  Partitions and resampling

A partition defines a held-out training/test split. Resampling defines a collection of training sets and their complementary assessment sets. The split design follows the intended use of the model: repeated individuals, groups, and temporal observations require corresponding separation.

7.1 A single split in memory

splits <- resample(
  iris,
  setup_StratSub(n_resamples = 1L, train_p = 0.8, seed = 2026L)
)
training_rows <- splits[[1L]]
dat_training <- iris[training_rows, ]
dat_test <- iris[-training_rows, ]

resample() returns a Resampler. Each indexed element contains training-row indices. Assessment rows are the complement of the selected training rows. Bootstrap training indices can contain repetitions.

7.2 Resampling methods

Constructor Training and assessment design
setup_KFold() Each fold is held out once; the remaining folds train the model.
setup_StratSub() Repeated stratified sampling without replacement within each training sample.
setup_Bootstrap() Sampling with replacement; unselected cases form the assessment set.
setup_StratBoot() Stratified bootstrap training samples.
setup_LOOCV() One case is held out per fit.
setup_Custom() Explicit lists of training-row indices.
folds <- resample(iris, setup_KFold(n_resamples = 5L, seed = 2026L))
folds
<Resampler>
     type: KFold
resamples: 
           Fold_1: 1, 2, 3, 4, ...
           Fold_2: 1, 2, 3, 4, ...
           Fold_3: 2, 3, 4, 6, ...
           Fold_4: 1, 4, 5, 6, ...
           Fold_5: 1, 2, 3, 5, ...
   config:
           <KFoldConfig>
            n_resamples: 5
           stratify_var: NULL
           strat_n_bins: 4
               id_strat: NULL
                   seed: 2026
custom <- setup_Custom(resamples = list(1:100, 51:150))

Categorical stratification uses the factor levels. Numeric stratification uses bins controlled by strat_n_bins. stratify_var supplies an explicit stratification variable. id_strat names a grouping column; within train(), that column groups the resamples and is excluded from the predictors.

7.3 Selection and assessment

Inner resampling selects hyperparameters. Outer resampling assesses the complete selection and fitting procedure. Each outer assessment set remains separate from fitting, preprocessing, and inner selection.

Sampling with replacement at the outer level can place replicated cases on both sides of an inner split. Use a design that preserves case separation when combining outer resampling and inner tuning. See nested tuning.

7.4 Auditable file partitions

partition() returns a manifest containing the rule and fingerprints of the source and partitions. With outdir, it writes training.parquet and test.parquet.

partition_dir <- tempfile("partitions-")
manifest <- partition(
  iris,
  setup_RandomPartition(train_p = 0.8, seed = 2026L),
  outdir = partition_dir
)
2026-10-08 02:53:10 ▶ Partitioned 150 cases into 120 training and 30 test (random). [partition]
manifest
$config
$config$method
[1] "random"

$config$train_p
[1] 0.8

$config$seed
[1] 2026


$source
$source$method
[1] "object"

$source$algorithm
[1] "sha256"

$source$encoding
[1] "r-serialize-v3"

$source$hash
[1] "e3449b68076a4e29c103a0dae0cce63885ab920883181b2c10eddcbb1c6ffc41"

$source$n_rows
[1] 150

$source$n_cols
[1] 5

$source$column_names
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     

$source$source
NULL

$source$language
[1] "R"

$source$data_structure
[1] "data.frame"


$outputs
$outputs$training
$outputs$training$path
[1] "/var/folders/cr/lgjpmnv97lg6qtnjt9kph7qw0000gn/T//Rtmpd7RO5X/partitions-df2e79cd92cd/training.parquet"

$outputs$training$fingerprint
$outputs$training$fingerprint$method
[1] "object"

$outputs$training$fingerprint$algorithm
[1] "sha256"

$outputs$training$fingerprint$encoding
[1] "r-serialize-v3"

$outputs$training$fingerprint$hash
[1] "a6a68f03b6f469f4e887dcc44af7bf473579a7e946e26cba3c11149aee5cf509"

$outputs$training$fingerprint$n_rows
[1] 120

$outputs$training$fingerprint$n_cols
[1] 5

$outputs$training$fingerprint$column_names
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     

$outputs$training$fingerprint$source
NULL

$outputs$training$fingerprint$language
[1] "R"

$outputs$training$fingerprint$data_structure
[1] "data.frame"


$outputs$training$n_rows
[1] 120


$outputs$test
$outputs$test$path
[1] "/var/folders/cr/lgjpmnv97lg6qtnjt9kph7qw0000gn/T//Rtmpd7RO5X/partitions-df2e79cd92cd/test.parquet"

$outputs$test$fingerprint
$outputs$test$fingerprint$method
[1] "object"

$outputs$test$fingerprint$algorithm
[1] "sha256"

$outputs$test$fingerprint$encoding
[1] "r-serialize-v3"

$outputs$test$fingerprint$hash
[1] "4a07435d9edb98847fab2cafc02805046058a1e145c9ecb0289103a7ada3a3aa"

$outputs$test$fingerprint$n_rows
[1] 30

$outputs$test$fingerprint$n_cols
[1] 5

$outputs$test$fingerprint$column_names
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"  "Species"     

$outputs$test$fingerprint$source
NULL

$outputs$test$fingerprint$language
[1] "R"

$outputs$test$fingerprint$data_structure
[1] "data.frame"


$outputs$test$n_rows
[1] 30
Constructor Separation rule
setup_RandomPartition() Random allocation using a training proportion and seed.
setup_TimePartition() Ordering by a named time column.
setup_GroupPartition() Allocation of whole groups from a named column.
setup_PredefinedPartition() Assignment from a column with training and test labels.

Partition manifests identify the files supplied to a portable training configuration.

© 2026 E.D. Gennatas