首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何计算ranger RF模型的AUC值?

如何计算ranger RF模型的AUC值?
EN

Stack Overflow用户
提问于 2017-08-14 22:23:24
回答 1查看 2.2K关注 0票数 3

如何计算ranger模型的AUC值?Ranger是randomForest算法在R中的快速实现。我使用以下代码来构建用于分类目的的ranger模型,并从模型中获得预测:

代码语言:javascript
复制
#Build the model using ranger() function
ranger.model <- ranger(formula, data = data_train, importance = 'impurity',   
write.forest = TRUE, num.trees = 3000, mtry = sqrt(length(currentComb)), 
classification = TRUE)
#get the prediction for the ranger model
pred.data <- predict(ranger.model, dat = data_test,)
table(pred.data$predictions)

但是我不知道如何计算AUC值

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-14 22:45:27

计算AUC的关键是有一种方法将测试样本从“最有可能为正”到“最不可能为正”排序。修改您的培训电话,使其包含probability = TRUEpred.data$predictions现在应该是一个类概率矩阵。记下与你的“积极”类相对应的列。此列提供了计算AUC所需的排名。

为了实际计算AUC,我们将使用Hand and Till, 2001中的公式(3)。我们可以按如下方式实现这个方程:

代码语言:javascript
复制
## An AUC estimate that doesn't require explicit construction of an ROC curve
auc <- function( scores, lbls )
{
  stopifnot( length(scores) == length(lbls) )
  jp <- which( lbls > 0 ); np <- length( jp )
  jn <- which( lbls <= 0); nn <- length( jn )
  s0 <- sum( rank(scores)[jp] )
  (s0 - np*(np+1) / 2) / (np*nn)
}   

其中scores是对应于正类的pred.data$predictions列,lbls是编码为二进制向量的相应测试标签(1表示正,0-1表示负)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45676745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档