Learn R Programming

mltools (version 0.3.4)

folds: Cross Validation Folds

Description

Map an object x into equal (or nearly equal) size folds. If x is a positive integer, a vector of FoldIDs of length matching x is returned, otherwise If x is a vector, a matching vector of FoldIDs is returned. If x is a data.table, a list of partitions of x is returned.

Usage

folds(x, nfolds = 5L, stratified = FALSE, seed = NULL)

Arguments

x

A positive integer, a vector of values or a data.table object

nfolds

How many folds?

stratified

If x is a vector then TRUE or FALSE indicating whether x's split the class's of x proportionally. If x is a data.table then stratified should be FALSE or the name of a column in x on which to perform stratification. Note that stratification is implemented for categorical, logical, AND numeric x

seed

Random number seed

Details

Convenient method for mapping an object into equal size folds, potentially with stratification

Examples

Run this code
# NOT RUN {
library(data.table)
folds(8, nfolds=2)
folds(alien.train$IsAlien, nfolds=2)
folds(alien.train$IsAlien, nfolds=2, stratified=TRUE, seed=2016)
folds(alien.train$IQScore, nfolds=2, stratified=TRUE, seed=2016)
folds(alien.train, nfolds=2, stratified="IsAlien", seed=2016)

# }

Run the code above in your browser using DataLab