[R] Test set and Train set in Caret package train function
Elahe chalabi
chalabi.elahe at yahoo.de
Sun Oct 22 16:13:43 CEST 2017
Hey all,
Does anyone know how we can get train set and test set for each fold of 5 fold cross validation in Caret package? Imagine if I want to do cross validation by random forest method, I do the following in Caret:
set.seed(12)
train_control <- trainControl(method="cv", number=5,savePredictions = TRUE)
rfmodel <- train(Species~., data=iris, trControl=train_control, method="rf")
first_holdout <- subset(rfmodel$pred, Resample == "Fold1")
str(first_holdout)
'data.frame': 90 obs. of 5 variables:
$ pred : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1
$ obs : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1
$ rowIndex: int 2 3 9 11 25 29 35 36 41 50 ...
$ mtry : num 2 2 2 2 2 2 2 2 2 2 ...
$ Resample: chr "Fold1" "Fold1" "Fold1" "Fold1" ...
Are these 90 observations in Fold1 used as training set? If yes then where is the test set for this fold?
thanks for any help!
Elahe
More information about the R-help
mailing list