train_test_from_folds: k-Fold Training and Test Partition Object

View source: R/trans_sample_random.R

train_test_from_foldsR Documentation

k-Fold Training and Test Partition Object

Description

Build one train/test split from a list of folds produced by cross-validation.

Usage

train_test_from_folds(folds, k)

Arguments

folds

Data already partitioned into folds.

k

Fold index to be used as the test set.

Details

The k-th fold is returned as the test set and all remaining folds are concatenated into the training set. This helper makes manual cross-validation loops easier to explain and reproduce.

Value

A list with two elements:

  • train: data frame containing all folds except the k-th.

  • test: data frame corresponding to the k-th fold.

Examples

# Create k-fold partitions of a dataset (e.g., iris)
folds <- k_fold(sample_random(), iris, k = 5)

# Use the first fold as the test set and combine the remaining folds
# for the training set
train_test_split <- train_test_from_folds(folds, k = 1)

# Display the training set
head(train_test_split$train)

# Display the test set
head(train_test_split$test)

daltoolbox documentation built on Nov. 23, 2026, 9:08 a.m.