cv_kfold: K-fold cross validation folds generation

View source: R/utils.R

cv_kfoldR Documentation

K-fold cross validation folds generation

Description

Generates folds for the classic k-fold cross validation where k mutually exclusive folds are generated and the training phase is done using k − 1 folds and the testing with the remaining one, which ensures all individuals are part of the testing once.

Usage

cv_kfold(records_number, k = 5)

Arguments

records_number

(numeric(1)) The expected number of elements to be included in the folds.

k

(numeric(1)) The number of folds. 5 by default.

Value

A list with k 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 5 folds of 2 elements (10 / 5) in testing set
folds <- cv_kfold(10, 5)
# Indices of training set in fold 1
folds[[1]]$training
# Indices of testing set in fold 1
folds[[1]]$testing
folds[[2]]$training
folds[[2]]$testing

folds <- cv_kfold(100, 30)
# List with indices of training and testing of fold 1
folds[[1]]
# List with indices of training and testing of fold 2
folds[[2]]
folds[[3]]
# ...
folds[[30]]

## End(Not run)


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