MLR3生存分析:如何同时执行特征选择和超参数调整并获得selected_features?



我正在尝试拟合coxph和参数模型,同时执行特征选择和超参数调整。下面有下面的代码,我可以在重采样中使用auto_fselector或auto_tuner,但不能同时使用这两种代码。我该怎么做?我需要3个嵌套的重新采样吗(内部用于特征选择,中间用于调整,外部用于性能评估(?在mlr中,我们先使用特性选择包装器,然后使用调优包装器,但不确定如何在mlr3中最好地做到这一点。

我还想在最后获得选定的功能。学习者$selected_features((似乎不适用于生存模型

task       = tsk("rats")
learner    = lrn("surv.coxph")
outer_cv   = rsmp("cv", folds = 10)$instantiate(task)
inner_cv   = rsmp("cv", folds = 10)$instantiate(task) 
Feat_select= auto_fselecter(method       = "random_search", 
learner      = learner,
resampling   = inner_cv,
measure      = msr("x"), 
term_evals   = 200)
model_tune = auto_tuner(method       = "irace", 
learner      = learner,
resampling   = inner_cv,
measure      = msr("x"),
search_space = ps())
model_res  = resample(task, model_tune , outer_cv, store_models = TRUE)

task       = tsk("rats")
learner2   = as_learner(po("encode") %>>% lrn("surv.cv_glmnet"))
learner2$selected_features()
Error: attempt to apply non-function
learner3 = mlr3extralearners::lrn("surv.rsfsrc")
learner$selected_features()
Error: attempt to apply non-function

您可以在mlr3:中嵌套AutoTunerAutoFSelector

library(mlr3tuning)
library(mlr3fselect)
task = tsk("pima")
at = auto_tuner(
method = "random_search",
learner = lrn("classif.rpart", cp = to_tune(0.01, 0.1)),
resampling = rsmp("cv", folds = 3),
measure = msr("classif.ce"),
term_evals = 5
)
afs = auto_fselector(
method = "random_search",
learner = at,
resampling = rsmp("cv", folds = 3),
measure = msr("classif.ce"),
term_evals = 5
)
rr = resample(task, afs, resampling = rsmp("cv", folds = 3), store_models = TRUE)
extract_inner_fselect_results(rr)

相关内容

  • 没有找到相关文章

最新更新