cvGen | R Documentation |
Generate indices for cross-validation and stratified cross-validation
cvGen(n, k) cvGenStratified(classVal,k) gatherFromList(lst)
n |
The number of instances in a data set. |
k |
The number of folds in cross-validation. |
classVal |
A vector of factors representing class values. |
lst |
A list of lists from which we collect results of the same components. |
The functions cvGen
and cvGenStratified
generate indices of instances from a data set which can be used in cross-validation.
The function cvGenStratified
generates the same distribution of class values in each fold.
The function gatherFromList
is an auxiliary function helping in collection of results, see the example below.
The functions cvGen
and cvGenStratified
return a vector of indices indicating fold membership i.e. from 1:k.
The function codegatherFromList returns a list with components containing elements of the same name.
Marko Robnik-Sikonja
CORElearn
.
data <- iris folds <- 10 foldIdx <- cvGen(nrow(data), k=folds) evalCore<-list() for (j in 1:folds) { dTrain <- data[foldIdx!=j,] dTest <- data[foldIdx==j,] modelCore <- CoreModel(Species~., dTrain, model="rf") predCore <- predict(modelCore, dTest) evalCore[[j]] <- modelEval(modelCore, correctClass=dTest$Species, predictedClass=predCore$class, predictedProb=predCore$prob ) destroyModels(modelCore) } results <- gatherFromList(evalCore) sapply(results, mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.