Caret Package: Stratified Cross Validation in Train Function

Is there a way to perform a stratified cross-validation using the train function so that it matches the model with a large unbalanced dataset? I know that direct cross-validation may be possible, but my categories are very unbalanced. I saw a discussion on this topic, but did not give a definitive answer.

Thanks in advance.

+5
source share
1 answer

There is a parameter called "index" that allows the user to specify an index for cross-validation.

folds <- 4 cvIndex <- createFolds(factor(training$Y), folds, returnTrain = T) tc <- trainControl(index = cvIndex, method = 'cv', number = folds) rfFit <- train(Y ~ ., data = training, method = "rf", trControl = tc, maximize = TRUE, verbose = FALSE, ntree = 1000) 
+7
source

Source: https://habr.com/ru/post/1244783/


All Articles