Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caret: undefined columns selected

Tags:

r

r-caret

I have been trying to get the below code to run in caret but get the error. Can anyone tell me how to trouble shoot it.

Error in [.data.frame(data, , lvls[1]) : undefined columns selected

library(tidyverse)
library(caret)

mydf <- iris

mydf <- mydf %>% 
  mutate(tgt = as.factor(ifelse(Species == 'setosa','Y','N'))) %>% 
  select(everything(), -Species)

trainIndex <- createDataPartition(mydf$tgt, p = 0.75, times = 1, list = FALSE)
train <- mydf[trainIndex,]
test <- mydf[-trainIndex,]

fitControl <- trainControl(method = 'repeatedcv',
                       number = 10,
                       repeats = 10,
                       allowParallel = TRUE,
                       summaryFunction = twoClassSummary)

fit_log <- train(tgt~.,
             data = train,
             method = "glm",
             trControl = fitControl,
             family = "binomial")
like image 915
John Smith Avatar asked Jan 31 '23 02:01

John Smith


1 Answers

You need to used classProbs = TRUE in your control function. The ROC curve is based on the class probabilities and the error is the summary function not finding those columns.

like image 196
topepo Avatar answered Feb 03 '23 04:02

topepo