如何使用 ROC 使用 caret 包选择最佳模型参数?
How to use ROC for choosing best model parameters using caret package?
我正在尝试基于插入符号构建一个 glm 模型 package.I 想使用 ROC 来选择最佳分类模型的 parameters.I 添加了 summaryFunction=twoClassSummary
和 classProbs = TRUE
到 trainControl
函数和
metric = "ROC"
到 train
函数。
这是我的代码:
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)
控制函数:
fitControl <- trainControl( method = "repeatedcv", number = 10,repeats = 10, summaryFunction=twoClassSummary,classProbs = TRUE)
型号:
glm <- train(target~ ., data = dat, method = "glm", trControl = fitControl, tuneLength = 4, metric = "ROC")
我收到这个错误:
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
我做错了什么?
尝试将 target
列设置为因子的代码:
dat$target<-as.factor(dat$target,labels=c("X0","X1"))
我正在尝试基于插入符号构建一个 glm 模型 package.I 想使用 ROC 来选择最佳分类模型的 parameters.I 添加了 summaryFunction=twoClassSummary
和 classProbs = TRUE
到 trainControl
函数和
metric = "ROC"
到 train
函数。
这是我的代码:
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)
控制函数:
fitControl <- trainControl( method = "repeatedcv", number = 10,repeats = 10, summaryFunction=twoClassSummary,classProbs = TRUE)
型号:
glm <- train(target~ ., data = dat, method = "glm", trControl = fitControl, tuneLength = 4, metric = "ROC")
我收到这个错误:
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
我做错了什么?
尝试将 target
列设置为因子的代码:
dat$target<-as.factor(dat$target,labels=c("X0","X1"))