【问题标题】:Evaluate ROC metric, caret package - R评估 ROC 指标,插入符号包 - R
【发布时间】:2018-06-10 15:42:22
【问题描述】:

我有这个代码:

model_nn <- train(
  Y ~ ., training,
  method = "nnet",
  metric = "ROC",
  trControl = trainControl(
    method = "cv", 
    number = 10,
    verboseIter = TRUE,
    classProbs = TRUE,
    summaryFunction = twoClassSummary
  )
)

nnprediction <- predict(model_nn, testing)
cmnn <-confusionMatrix(nnprediction,testing$Y)
print(cmnn)

哪个有效。但是,我无法评估使用混淆矩阵命令的 ROC 指标性能有多好。我该如何评估它,以便尝试一组不同的变量和/或机器学习算法来提高 ROC 性能?

PS:因变量是两个类的因子。

【问题讨论】:

    标签: r machine-learning r-caret roc auc


    【解决方案1】:

    只需输入model_nn 即可为您提供训练期间使用的不同设置的 AUC 分数;这是一个示例,使用iris 数据的前 100 条记录(2 类):

    library(caret)
    library(nnet)
    
    data(iris)
    iris_reduced <- iris[1:100,]
    iris_reduced <- droplevels(iris_reduced, "virginica")
    
    model_nn <- train(
      Species ~ ., iris_reduced,
      method = "nnet",
      metric = "ROC",
      trControl = trainControl(
        method = "cv", 
        number = 5,
        verboseIter = TRUE,
        classProbs = TRUE,
        summaryFunction = twoClassSummary
      )
    )
    
    model_nn
    

    结果:

    Neural Network 
    
    100 samples
      4 predictors
      2 classes: 'setosa', 'versicolor' 
    
    No pre-processing
    Resampling: Cross-Validated (5 fold) 
    Summary of sample sizes: 80, 80, 80, 80, 80 
    Resampling results across tuning parameters:
    
      size  decay  ROC  Sens  Spec
      1     0e+00  1.0  1.0   1   
      1     1e-04  0.8  0.8   1   
      1     1e-01  1.0  1.0   1   
      3     0e+00  1.0  1.0   1   
      3     1e-04  1.0  1.0   1   
      3     1e-01  1.0  1.0   1   
      5     0e+00  1.0  1.0   1   
      5     1e-04  1.0  1.0   1   
      5     1e-01  1.0  1.0   1   
    
    ROC was used to select the optimal model using  the largest value.
    The final values used for the model were size = 1 and decay = 0.1.
    

    顺便说一句,这里的“ROC”一词有些误导:返回的当然不是 ROC(这是一个 曲线,而不是数字),而是 ROC 曲线下的面积,即AUC(在trainControl中使用metric='AUC'具有相同的效果)。

    【讨论】:

      猜你喜欢
      • 2014-05-28
      • 2017-05-19
      • 2014-03-06
      • 2019-09-29
      • 2018-11-11
      • 2014-06-15
      • 2018-02-22
      • 2016-10-06
      • 1970-01-01
      相关资源
      最近更新 更多