代码之家  ›  专栏  ›  技术社区  ›  user2947767

如何计算ranger射频模型的AUC值?

  •  3
  • user2947767  · 技术社区  · 7 年前

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

    #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值

    知道吗?

    1 回复  |  直到 6 年前
        1
  •  3
  •   Artem Sokolov    7 年前

    计算AUC的关键是有一种方法可以将测试样本从“最有可能呈阳性”到“最不可能呈阳性”进行排序。修改您的培训电话以包括 probability = TRUE pred.data$predictions 现在应该是一个类概率矩阵。记下与“肯定”类对应的列。本栏提供了计算AUC所需的排名。

    为了实际计算AUC,我们将使用公式(3) Hand and Till, 2001

    ## 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。数据$预测 对应于正类,并且 lbls 相应的测试标签是否编码为二进制向量( 1 0 -1 对于负数)。