Perform cross validation on given data.
f should be a function that takes 4 inputs xtrain, ytrain,
xtest, ytest, fits a model based on xtrain, ytrain,
applies the fitted model to xtest, and returns a goodness of fit
measure based on comparing the predicted and actual ytest.
crossval
returns an array containing the values returned by f
for every cross-validation fold or resampling applied to the given data.
X should be an n by m matrix of predictor values
y should be an n by 1 vector of predicand values
params may include parameter-value pairs as follows:
"KFold"
Divide set into k equal-size subsets, using each one successively for validation.
"HoldOut"
Divide set into two subsets, training and validation. If the value k is a fraction, that is the fraction of values put in the validation subset (by default k=0.1); if it is a positive integer, that is the number of values in the validation subset.
"LeaveOut"
Leave-one-out partition (each element is placed in its own subset). The value is ignored.
"Partition"
The value should be a cvpartition object.
"Given"
The value should be an n by 1 vector specifying in which partition to put each element.
"stratify"
The value should be an n by 1 vector containing class
designations for the elements, in which case the "KFold"
and
"HoldOut"
partitionings attempt to ensure each partition
represents the classes proportionately.
"mcreps"
The value should be a positive integer specifying the number of times
to resample based on different partitionings. Currently only works with
the partition type "HoldOut"
.
Only one of "KFold"
, "HoldOut"
, "LeaveOut"
,
"Given"
, "Partition"
should be specified. If none is
specified, the default is "KFold"
with k = 10.
See also: cvpartition.
Package: statistics