R中的多个AUC

数据挖掘 机器学习 r
2022-03-11 11:59:37

我一直在为二元决策树使用可解释的机器学习包,称为 IAI。

长话短说:这里的核心方法被称为“最优分类器”(它不使用随机森林或 XGBoost 等贪婪启发式算法。而是组合评估所有树以获得全局优化)。

因此,鉴于这三个模型的相反优点,我想在一张图上比较 AUC。假设我有三个存储的图:

最优分类器:

x <- iai::roc_curve(grid, test_X, test_y, positive_label = 1)

随机森林:

y <- iai::roc_curve(grid, test_X, test_y, positive_label = 1)

XGBoost

z <- iai::roc_curve(grid, test_X, test_y, positive_label = 1)

是否可以将这些组合在一个情节中?我已经尝试过 pROC 和“添加真实”的论点。但我没有任何运气。

我附上了我的代码的来源,以防万一。真的很感激一些帮助。

最优分类器 AUC:

https://docs.interpretable.ai/stable/IAI-R/quickstart/ot_classification/

贪心方法 AUC

https://docs.interpretable.ai/stable/IAI-R/quickstart/heur_classification/

1个回答

包中的roc功能pROC允许您提取灵敏度和特异性值。我将在下面举一个例子。请记住,y-轴是灵敏度,但x-轴是1specificity.

library(pROC)
set.seed(2021)
N <- 1000
x1 <- rnorm(N)
x2 <- rnorm(N)
x3 <- rnorm(N)
z <- x1 + x2 + x3
pr <- 1/(1 + exp(-z))
y <- rbinom(N, 1, pr)
L1 <- glm(y ~ x1, family = binomial)
L2 <- glm(y ~ x1 + x2, family = binomial)
L3 <- glm(y ~ x1 + x2 + x3, family = binomial)
pred1 <- 1/(1 + exp(-predict(L1)))
pred2 <- 1/(1 + exp(-predict(L2)))
pred3 <- 1/(1 + exp(-predict(L3)))
roc1 <- pROC::roc(y, pred1)
roc2 <- pROC::roc(y, pred2)
roc3 <- pROC::roc(y, pred3)
plot(1 - roc1$specificities, roc1$sensitivities, col = 'black')
points(1 - roc2$specificities, roc2$sensitivities, col = 'red')
points(1 - roc3$specificities, roc3$sensitivities, col = 'blu

请记住,统计学家不一定喜欢 ROC 曲线。