slb.xval.split: Cross-Validation Data Splitter

Description Usage Arguments Value Author(s) Examples

View source: R/xval.R

Description

A function to split a dataset into training and testing sets for cross validation.

Usage

1
slb.xval.split(X, Y, k = "loo", reverse = FALSE, ...)

Arguments

X

[n, d] the data with n samples in d dimensions.

Y

[n] vector or [n, r] array the responses for the samples.

k

the cross-validated method to perform. Defaults to 'loo'.

  • if k == round(k), performed k-fold cross-validation.

  • if k == 'loo', performs leave-one-out cross-validation.

reverse

whether to flip the training and testing partitions. Defaults to FALSE.

  • if isTRUE(reverse), flips the training and testing partitions, such that cross-validation will be performed with 1 training fold and k-1 testing folds.

  • if !isTRUE(reverse), standard cross-validation, with k-1 training folds and 1 testing fold.

...

optional args.

Value

sets the cross-validation sets as an object of class "XV" containing the following:

train

is [n - n/k] vector if isTRUE(reverse), and a [n/k] vector otherwise.

test

is [n/k] vector if isTRUE(reverse), and a [n - n/k] vector otherwise.

Author(s)

Eric Bridgeford

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# prepare data for 10-fold validation
library(slb)
data(SWD)
sets.xval.10fold <- slb.xval.split(SWD$X, SWD$Y, k=10)

# prepare data for loo validation
sets.xval.loo <- slb.xval.split(SWD$X, SWD$Y, k='loo')

# reverse the training and testing sets
sets.xval.10fold.rev <- slb.xval.split(SWD$X, SWD$Y, k=10, reverse=TRUE)

neurodata/slbR documentation built on May 22, 2019, 2:41 p.m.