mlr3机器学习AUC的置信区间提取

如果你在mlr3拿到机器学习的预测数据

ROC 过程原理探索

假设数据

df <- data.frame(A=iris$Sepal.Length,
group=sample(x = c(0,1),size = 150,replace = T))

分组为 0,1 # 变量A为连续性变量

library(pROC)
roc_obj <- roc(df g r o u p , d f group, df group,dfA, levels = c(0, 1),ci=T)
auc(roc_obj)
ci.auc(roc_obj)

如果你直接在机器学习拿到预测数据

fit <- lm(df g r o u p   d f group~df group dfA)
pre_df <- predict(fit,df)

roc_obj_2 <- roc(df$group, pre_df, levels = c(0, 1),ci=T)
auc(roc_obj_2)

实测demo

# 在train的性能
prediction_train_rf = learner_rf$predict(task, row_ids = train_id)
prediction_train_rf$confusion
prediction_train_rf$score(msr("classif.auc"))
p_rf_train=autoplot(prediction_train_rf,type = "roc")
p_rf_train

# 在test的性能
prediction_test_rf = learner_rf$predict(task, row_ids = test_id)
prediction_test_rf$confusion
prediction_test_rf$score(msr("classif.auc"))
p_rf_test=autoplot(prediction_test_rf,type = "roc")
p_rf_test


# train的AUC和CI,多ROC线准备
library(pROC)
# train的AUC和CI,多ROC线准备
roc_obj_rf_train <- roc(prediction_train_rf$truth, 
                        prediction_train_rf$prob[,1], ci=T)
auc(roc_obj_rf_train);ci.auc(roc_obj_rf_train)

# 【与上面不一致】 不需要判断 prob 选哪个
# roc_obj_rf_train <- roc(prediction_test_rf$truth, 
#                  ifelse(
#                    prediction_test_rf$truth==1,
#                    prediction_test_rf$prob[,1],
#                    prediction_test_rf$prob[,2]
#                  ), ci=T)
# auc(roc_obj_rf_train);ci.auc(roc_obj_rf_train)
# test的AUC和CI,多ROC线准备
roc_obj_rf_test <- roc(prediction_test_rf$truth, 
                       prediction_test_rf$prob[,1], ci=T)
auc(roc_obj_rf_test);ci.auc(roc_obj_rf_test)
# 
pROC::plot.roc(roc_obj_rf_test)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值