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

Splits a dataset into training and test sets based on k-fold cross-validation. The function takes a list of data partitions (folds) and a specified fold index k. It returns the data corresponding to the k-th fold as the test set, and combines all other folds to form the training set.

Usage

train_test_from_folds(folds, k)

Arguments

folds

data partitioned into folds

k

k-fold for test set, all reminder for training set

Value

returns a list with two elements:

  • train: A data frame containing the combined data from all folds except the k-th fold, used as the training set.

  • test: A data frame corresponding to the k-th fold, used as the test set.

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. 3, 2024, 9:06 a.m.