How to implement a hold-out validation in R

二次信任 提交于 2019-12-03 21:52:39

I think that maybe you want to use 1/5th of the data as a test set and train using the other 4/5ths?

If that is the case, you should used createDataPartition first and let train do the rest. For example:

> library(caret)
> library(mlbench)
> data(Sonar)
> 
> set.seed(1)
> in_train <- createDataPartition(Sonar$Class, p = 4/5, list = FALSE)
> 
> training <- Sonar[ in_train,]
> testing  <- Sonar[-in_train,]
> 
> nrow(Sonar)
[1] 208
> nrow(training)
[1] 167
> nrow(testing)
[1] 41
> 
> lda_fit <- train(Class ~ ., data = training, method = "lda")
> lda_fit
Linear Discriminant Analysis 

167 samples
 60 predictors
  2 classes: 'M', 'R' 

No pre-processing
Resampling: Bootstrapped (25 reps) 

Summary of sample sizes: 167, 167, 167, 167, 167, 167, ... 

Resampling results

  Accuracy  Kappa  Accuracy SD  Kappa SD
  0.71      0.416  0.0532       0.108  

Max

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!