cv_random: Random cross validation folds generation

View source: R/utils.R

cv_randomR Documentation

Random cross validation folds generation

Description

Generates folds for cross validation where you specify the number of folds and the proportion of testing. In each fold a sample without replacement of the specified proportion of testing individuals is taken to be the testing set and all the remaining ones to be the training set.

Usage

cv_random(records_number, folds_number = 5, testing_proportion = 0.2)

Arguments

records_number

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

folds_number

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

testing_proportion

(numeric(1)) The proportion of elements to be included in the testing set in each fold. 0.2 by default.

Value

A list with folds_number 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
folds <- cv_random(10, 5, 0.2)
# 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

# Generates 30 folds with 30 elements in testing set
folds <- cv_kfold(100, 30, 0.3)
# 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.