使用rmlr3从作为管道一部分的所有模型中提取预测



下面,我创建了mlr3图,并在样本数据集上训练它。

我知道如何为最终阶段(回归平均)创建预测,但是有可能在平均之前得到模型的预测吗?目标是将单个模型的性能与最终模型进行比较。

附加问题,单个模型本身可以自动调谐吗?如果是,如何将它们合并到管道中?

library(mlr3)
library(mlr3learners)
library(mlr3pipelines)
library(mlr3tuning)
# task
mlr_tasks
task = tsk("mtcars")
# graph
learners_l = list(
ranger = lrn("regr.ranger", id = "ranger"),
xgboost = lrn("regr.xgboost", id = "xgboost")
)
choices = c("ranger", "lm", "kknn", "xgboost")
learners = gunion(learners_l) %>>%
po("regravg", innum = length(learners_l))
# create graph
graph = gunion(list(
ranger = lrn("regr.ranger", id = "ranger"),
xgboost = lrn("regr.xgboost", id = "xgboost")
)) %>>%
po("regravg", innum = length(learners_l))
plot(graph)
graph_learner = as_learner(graph)
# search space
search_space = ps(
ranger.ranger.max.depth = p_fct(levels = c(2L, 3L))
)
# auto tuner
at = auto_tuner(
tuner = tnr("grid_search"),
learner = graph_learner,
resampling = rsmp("holdout"),
measure = msr("regr.mse"),
search_space = search_space,
term_evals = 2,
store_models = TRUE
)
# train
at$train(task)
# IS IT POSSIBLE TO EXTRACT PREDICTIONS OF RANGER AND XGBOOST TO COMPARE IT WITH ENSAMBLE?

训练好的学习器位于$graph_model插槽。

at$model$learner$graph_model$pipeops$ranger.ranger$predict(list(task))
at$model$learner$graph_model$pipeops$xgboost.xgboost$predict(list(task))

附加问题,单个模型本身可以自动调谐吗?如果是,如何将它们合并到管道中?

是的。AutoTuner对象是学习器,可以像学习器一样使用。你必须决定这是否有意义。

相关内容

  • 没有找到相关文章

最新更新