R 意外值

R 意外值,r,roc,auc,R,Roc,Auc,在对一组我们认为可以预测肿瘤和正常人的分子运行逻辑回归模型后,我有以下预测 Predicted class T N T 29 5 Actual class N 993 912 我有一个分数列表,范围从预测值到0个正数。然后,我在data.fra

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

                  Predicted   class     
                      T        N          
                 T   29        5
  Actual class
                 N   993      912           
我有一个分数列表,范围从预测值到0个正数。然后,我在data.frame中有另一列,该列指示从模型中预测的标签1==肿瘤和0==法线。我尝试使用libraryROC以以下方式计算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)
电话:

AUC等于1。我不确定我是否完全正确运行,或者我在解释结果时可能做错了什么,因为很少有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

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


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

您的x.measure中有一个输入错误,应该会引发错误。你必须为而不是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)

你到底给这些函数提供了什么?A会很有帮助。也许你需要gto做一些像AucroPred、labels之类的事情?对不起,我在复制和粘贴代码到这里的过程中犯了一个错误,但原始的是fpr。它们是相同的,但其中一个与预测相反。纯粹的机会会给出0.5的AUC,因此小于0.5的一切都最好相反。@Jasper你是对的,完全忘记了这一点!
require(AUC)
auc = AUC::auc(AUC::roc(pred, y))
print(auc) # 0.4569243
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)