cv_leve_one_group_out: Leave one group out cross validation folds generation

View source: R/utils.R

cv_leve_one_group_outR Documentation

Leave one group out cross validation folds generation

Description

Generates folds for the leave one group out cross validation. In each fold on group is taken to be the testing set and all the remaining ones to be the training set.

Usage

cv_leve_one_group_out(data)

Arguments

data

(vector) The categorical data considered to stratify the folds.

Value

A list with length(unique(data)) elements where each element is a named list with the elements training wich includes the indices of those records to be part of the training set and testing wich includes the indices of those records to be part of the testing set. Training and testing sets of each fold are exhaustive and mutually exclusive.

Examples

## Not run: 
# Generates random data
data <- c(rep("A", 10), rep("B", 20), rep("C", 30))
folds <- cv_leve_one_group_out(data)
# Indices of training set in fold 1
folds[[1]]$training
# Indices of testing set in fold 1
folds[[1]]$testing

# Verify fold 1 only contains elements of group A
table(data[folds[[1]]$training])
table(data[folds[[1]]$testing])
# Verify fold 2 only contains elements of group B
table(data[folds[[2]]$training])
table(data[folds[[2]]$testing])
# Verify fold 3 only contains elements of group C
table(data[folds[[3]]$training])
table(data[folds[[3]]$testing])

## End(Not run)


brandon-mosqueda/SKM documentation built on Feb. 8, 2025, 5:24 p.m.