I'm trying to build an glm model based on caret package.I would like to use the ROC for choosing the best classification model's parameters.I added summaryFunction=twoClassSummary
and classProbs = TRUE
to the trainControl
function and
metric = "ROC"
to the train
function.
Here is my code:
library('caret')
dat <- read.table(text = " target birds wolfs snakes
+ 0 3 9 7
+ 1 3 8 4
+ 1 1 2 8
+ 0 1 2 3
+ 0 1 8 3
+ 1 6 1 2
+ 0 6 7 1
+ 1 6 1 5
+ 0 5 9 7
+ 1 3 8 7
+ 1 4 2 7
+ 0 1 2 3
+ 0 7 6 3
+ 1 6 1 1
+ 0 6 3 9
+ 1 6 1 1 ",header = TRUE)
The control function:
fitControl <- trainControl( method = "repeatedcv", number = 10,repeats = 10, summaryFunction=twoClassSummary,classProbs = TRUE)
The model:
glm <- train(target~ ., data = dat, method = "glm", trControl = fitControl, tuneLength = 4, metric = "ROC")
I got this error:
Error in evalSummaryFunction(y, wts = weights, ctrl = trControl, lev = classLevels, :
train()'s use of ROC codes requires class probabilities. See the classProbs option of trainControl()
In addition: Warning message:
In train.default(x, y, weights = w, ...) :
cannnot compute class probabilities for regression
What am I'm doing wrong?