简体   繁体   English

如何将分类阈值定义为学习器的(超)参数,以便在 R 的 mlr3 package 中进行调整?

[英]How to define the classification threshold as a (hyper)parameter of a learner for tuning in mlr3 package in R?

there is a function to tune threshold for say a binary classification described here: https://mlr3pipelines.mlr-org.com/reference/mlr_pipeops_t.nethreshold.html有一个 function 来调整这里描述的二进制分类的阈值: https://mlr3pipelines.mlr-org.com/reference/mlr_pipeops_t.nethreshold.html

Here's my failed attempt:这是我失败的尝试:

  RF_lrn <- lrn("classif.rfsrc", id = "rf", predict_type = "prob")
  RF_lrn$param_set$values = list(na.action = "na.impute", seed = -123)
  single_pred_rf = po("subsample", frac = 1, id = "rf_ss") %>>%
    po("learner", RF_lrn) %>>% po("tunethreshold")

That did not work in my mlr3 pipeline and I did not find any solution explained anywhere so here is my code:这在我的 mlr3 管道中不起作用,我没有在任何地方找到任何解释的解决方案,所以这是我的代码:

   xgb_lrn <-
    lrn("classif.xgboost", id = "xgb", predict_type = "prob")
  single_pred_xgb = po("subsample", frac = 1, id = "xgb_ss") %>>%
    po("learner", xgb_lrn)
  
    lrnrs <- list(
      RF_lrn,
      xgb_lrn)
    
    lrnrs <- lapply(lrnrs, function(x) {
      GraphLearner$new(po("learner_cv", x) %>>% po("tunethreshold",
                                                   param_vals = list(
                                                     measure = "classif.prauc"
                                                   )
      ))
    })
    library("GenSA")
    lrnrs$RF_lrn <- auto_tuner(
      learner =  RF_lrn,
      search_space = ps(
        ntree = p_int(lower = 20, upper = 300),
        mtry = p_int(lower = 2, upper = 5),
        nodesize = p_int(lower = 1, upper = 7)
      ),
      resampling = rsmp("bootstrap", repeats = 2, ratio = 0.8),
      measure = msr("classif.prauc"),
      term_evals = 100,
      method = "random_search"
    )

which somehow works but I want the decision threshold to be tuned as a parameter the same way I tune other hyperparameters using the random search in benchmarking/cross validation.它以某种方式起作用,但我希望将决策阈值作为参数进行调整,就像我在基准测试/交叉验证中使用随机搜索调整其他超参数一样。 Any solution?任何解决方案? Thanks in advance提前致谢

the solution is to use po("threshold") instead of po("t.nethreshold") as suggested in the comments and this mlr gallery example解决方案是使用po("threshold")而不是评论中建议的po("t.nethreshold")和这个mlr gallery example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM