I have an imbalanced data set with two classes therefore I thought I could use ROC as a metric instead of Accuracy to tune my model in R using caret package (I am trying different methods such as rpart, rf..etc). I thought we could extract probabilities and use ROC as a metric in decision tree type algorithms as well using caret. I illustrate my problem using a data set in caret below. There are three classes in this data but I redefined and created two classes for illustration purposes. I don't understand why the below code gives this error (I keep getting the same error when I change the method). I appreciate your help.
Error in train.default(x, y, weights = w, ...) : final tuning parameters could not be determined
In addition: Warning messages:
- In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures.
- In train.default(x, y, weights = w, ...) : missing values found in aggregated results'
library(caret)
data(iris)
iris$Species <- as.character(iris$Species)
iris$Species[which(iris$Species=='virginica')] <- 'versicolor'
iris$Species <- as.factor(iris$Species)
x <- iris[, !(colnames(iris) == "Species")]
y <- iris$Species
fitControl <- trainControl(method = "cv", number=5, classProbs = TRUE,
summaryFunction = twoClassSummary)
RF <- train(y = y, x=x,
method="rpart",metric="ROC",
trControl=fitControl)