[R] cross validation

Liaw, Andy andy_liaw at merck.com
Fri Jan 21 12:29:03 CET 2005


One way is to create an indicator vector that indicate which `fold' a case
should belong to.  Something like:

fold <- 10
idx <- sample(fold, n, replace=TRUE)
for (I in 1:fold) {
   train.dat <- dat[idx != i,]
   test.dat <- dat[idx == i,]
   ...
}

Also see the errorest() function in the ipred package.  It is more careful
in making sure the folds are as close in size as possible, and can do
stratified splits.

Andy


> From: kolluru ramesh
> 
> How to select training data set and test data set from the 
> original data for performing cross-validation
> 
> 		
> ---------------------------------
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list