MLInterfaces (version 1.48.0)

xvalSpec: container for information specifying a cross-validated machine learning exercise

Description

container for information specifying a cross-validated machine learning exercise

Usage

xvalSpec( type, niter=0, partitionFunc=function(data, classLab, iternum ) { (1:nrow(data))[-iternum] }, fsFun = function(formula, data) formula )

Arguments

type
a string, "LOO" indicating leave-one-out cross-validation, or "LOG" indicating leave-out-group, or "NOTEST", indicating the entire dataset is used in a single training run.
niter
numeric specification of the number of cross-validation iterations to use. Ignored if type is "LOO".
partitionFunc
function, with parameters data (bound to data.frame), clab (bound to character string), iternum (bound to numeric index into sequence of 1:niter). This function's job is to provide the indices of training cases for each cross-validation step. An example is balKfold.xvspec, which computes a series of indices that are approximately balanced with respect to frequency of outcome types.
fsFun
function, with parameters formula, data. The function must return a formula suitable for defining a model on the basis of the main input data. A candidate fsFun is given in example for fsHistory function.

Value

An instance of classifierOutput, with a special structure. The RObject return slot is populated with a list of niter cross-validation results. Each element of this list is itself a list with two elements: test.idx (the indices of the test set for the associated cross-validation iteration, and mlans, the classifierOutput generated at each iteration. Thus there are classifierOutput instances nested within the main classifierOutput returned when a xvalSpec is used.

Details

If type == "LOO", no other parameters are inspected. If type == "LOG" a value for partitionFunc must be supplied. We recommend using balKfold.xvspec(K). The values of niter and K in this usage must be the same. This redundancy will be removed in a future upgrade.

If the parallel package is attached and symbol mc_fork is loaded, cross-validation will be distributed to cores using mclapply.

Examples

Run this code
library("MASS")
data(crabs)
set.seed(1234)
#
# demonstrate cross validation
#
nn1cv = MLearn(sp~CW+RW, data=crabs, nnetI, xvalSpec("LOG",
   5, balKfold.xvspec(5)), size=3, decay=.01 )
nn1cv
confuMat(nn1cv)
names(RObject(nn1cv)[[1]])
RObject(RObject(nn1cv)[[1]]$mlans)

Run the code above in your browser using DataCamp Workspace