How to retrieve a fold while subsampling for class imbalance using caret

Viewed 17

I have a class imbalance issue with my data, and following the guide here, I'm trying to downsample during a cv. I'd like to be able to inspect individual folds after running the model, but when I attempt to pull an individual fold from the training set I don't see balanced classes like I expected. Does the downsampling occur after the creation of the fold? If so, how would I retrieve those indices? A sample:

set.seed(2969)
imbal_train <- twoClassSim(10000, intercept = -20, linearVars = 20)
tr_ctrl <- trainControl(method = "cv", number = 5,
             classProbs = TRUE,
             p=0.5,
             summaryFunction = twoClassSummary,
             sampling = "down")
testModel<-train(Class ~ ., 
                 data = imbal_train,
                 method = "rf",
                 metric = "ROC",
                 trControl = tr_ctrl)
fold1<-imbal_train[testModel$control$index$Fold1,]
table(fold1$Class)

Class1 7529 Class2 472

0 Answers
Related