【问题标题】:AUC unexpected valueAUC 意外值
【发布时间】:2017-08-15 03:25:22
【问题描述】:

在对一组我们认为可以预测肿瘤与正常情况的分子运行逻辑回归模型后,我有以下预测。

                  Predicted   class     
                      T        N          
                 T   29        5
  Actual class
                 N   993      912           

我有一个分数列表,范围从预测 0(正数)。然后我的data.frame 中有另一列,表示模型预测的标签(1== 肿瘤和 0== 正常)。我尝试通过以下方式使用library(ROC) 计算 ROC:

 pred = prediction(prediction, labels)     
 roc = performance(pred, "tpr", "fpr")   
 plot(roc, lwd=2, colorize=TRUE)   

使用:

       roc_full_data <- roc(labels, prediction)
       rounded_scores <- round(prediction, digits=1)
       roc_rounded <- roc(labels, prediction)

呼叫:

       roc.default(response = labels, predictor = prediction)
       Data: prediction in 917 controls (category 0) < 1022 cases (category1).
       Area under the curve: 1

AUC 等于 1。我不确定我是否全部正确运行,或者我可能在解释我的结果时做错了什么,因为 AUC 等于 1 的情况很少见。

谁能帮帮我?

最好的

【问题讨论】:

  • 你到底为这些函数提供了什么? reproducible example 会很有帮助。
  • 也许你需要 gto 做一些类似auc(roc(pred, labels))的事情?

标签: r roc auc


【解决方案1】:

我使用pROC来计算AUC:

require(pROC)
set.seed(1)
pred = runif(100)
y = factor(sample(0:1, 100, TRUE))
auc = as.numeric(roc(response = y, predictor = pred)$auc)
print(auc) # 0.5430757

或者

require(AUC)
auc = AUC::auc(AUC::roc(pred, y))
print(auc) # 0.4569243

我无法解释为什么结果不同。

编辑:上述 aucs 总和为 1.0,因此其中一个库自动“反转”了预测。

【讨论】:

  • 它们是相同的,但是一个倒置了预测。纯粹的机会会给出 0.5 的 AUC,所以小于这个值的所有东西都最好反其道而行之。
  • @Jasper 你说得对,完全忘记了!
【解决方案2】:

您的 x.measure 中有一个错字,应该会引发错误。你有“for”而不是“fpr”。试试下面的代码。

performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf)

# add a reference line to the graph
abline(a = 0, b = 1, lwd = 2, lty = 2)

# calculate AUC
perf.auc <- performance(pred, measure = "auc")
str(perf.auc)
as.numeric(perf.auc@y.values)

【讨论】:

  • 对不起,我在从我的代码复制粘贴到这里的过程中犯了一个错误,但原来是 fpr。
猜你喜欢
  • 1970-01-01
  • 2019-06-09
  • 2019-07-08
  • 2019-08-16
  • 2012-07-28
  • 2013-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多