[英]How to define the classification threshold as a (hyper)parameter of a learner for tuning in mlr3 package in R?
有一個 function 來調整這里描述的二進制分類的閾值: https://mlr3pipelines.mlr-org.com/reference/mlr_pipeops_t.nethreshold.html
這是我失敗的嘗試:
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")
這在我的 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"
)
它以某種方式起作用,但我希望將決策閾值作為參數進行調整,就像我在基准測試/交叉驗證中使用隨機搜索調整其他超參數一樣。 任何解決方案? 提前致謝
解決方案是使用po("threshold")
而不是評論中建議的po("t.nethreshold")
和這個mlr gallery example
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.