AUC 意外值
AUC unexpected value
运行在一组分子上建立逻辑回归模型后,我有以下预测,我们认为这些分子可以预测肿瘤与正常人。
Predicted class
T N
T 29 5
Actual class
N 993 912
我有一个分数列表,范围从预测 <0(负数)到预测 >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.
我用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,因此其中一个库自动 'inverted' 预测。
您的 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)
运行在一组分子上建立逻辑回归模型后,我有以下预测,我们认为这些分子可以预测肿瘤与正常人。
Predicted class
T N
T 29 5
Actual class
N 993 912
我有一个分数列表,范围从预测 <0(负数)到预测 >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.
我用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,因此其中一个库自动 'inverted' 预测。
您的 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)