3

嗨,我的名字是 Abhi,我正在使用插入符号来构建基于 gbm 树的模型。但是,我不想使用准确性,而是使用 roc 作为我的指标

这是我到目前为止的代码

myTuneGrid <- expand.grid(n.trees = 500,interaction.depth = 11,shrinkage = 0.1)
fitControl <- trainControl(method = "repeatedcv", number = 7,repeats = 1, verboseIter = FALSE,returnResamp = "all",classProbs = TRUE)
myModel <- train(Cover_Type ~ .,data = modelData,method = "gbm",trControl = fitControl,tuneGrid = myTuneGrid,metric='roc')

但是,当我运行此代码时,我会收到警告

Warning message:
In train.default(x, y, weights = w, ...) :
The metric "roc" was not in the result set. Accuracy will be used instead.

如何强制我的模型使用 roc 而不是准确性。我在这里做错了什么?

4

2 回答 2

1

这是源代码的github项目的链接吗? https://github.com/rseiter/PracticalMLProject/blob/master/multiClassSummary.R

于 2014-10-14T19:34:10.160 回答
0

如果您指定并使用(而不是在您的代码中)twoClassSummary(),它应该可以工作:trainControlmetric="ROC"method="roc"

df = iris
df$Species =factor(ifelse(df$Species=="versicolor","v","o"))

fitControl <- trainControl(method = "cv",returnResamp = "all",
classProbs = TRUE,summaryFunction = twoClassSummary)

myModel <- train(Species ~ .,data = df,method = "gbm",trControl = fitControl,metric='ROC')

Stochastic Gradient Boosting 

150 samples
  4 predictor
  2 classes: 'o', 'v' 

No pre-processing
Resampling: Cross-Validated (10 fold) 
Summary of sample sizes: 135, 135, 135, 135, 135, 135, ... 
Resampling results across tuning parameters:

  interaction.depth  n.trees  ROC    Sens  Spec
  1                   50      0.988  0.98  0.92
  1                  100      0.980  0.97  0.94
  1                  150      0.972  0.96  0.94
  2                   50      0.984  0.97  0.94
  2                  100      0.976  0.96  0.92
  2                  150      0.960  0.97  0.92
  3                   50      0.984  0.97  0.94
  3                  100      0.968  0.98  0.92
  3                  150      0.968  0.96  0.92

Tuning parameter 'shrinkage' was held constant at a value of 0.1

Tuning parameter 'n.minobsinnode' was held constant at a value of 10
ROC was used to select the optimal model using the largest value.
The final values used for the model were n.trees = 50, interaction.depth =
 1, shrinkage = 0.1 and n.minobsinnode = 10.
于 2020-06-25T21:07:40.427 回答