folds {mltools}R Documentation

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

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)


[Package mltools version 0.3.5 Index]