我正在使用mlr3
一系列软件包和超频带方法来调整机器学习模型。一切进展顺利,但我无法弄清楚如何预测使用超频带找到新数据的最佳配置。
是否可以直接使用存储在结果中的信息来执行此操作instance
- 或者我是否需要提取最佳配置(即instance$result
),然后使用这些参数拟合一个新模型,然后我可以用它来预测?
在下面的示例中(从 mlr3 书中借用)如何使用存储的信息instance
来预测新数据?
library(paradox)
library(mlr3tuning)
#> Loading required package: mlr3
library(mlr3hyperband)
library(mlr3pipelines)
set.seed(123)
# extend "classif.rpart" with "subsampling" as preprocessing step
ll = po("subsample") %>>% lrn("classif.rpart")
# extend hyperparameters of "classif.rpart" with subsampling fraction as budget
search_space = ps(
classif.rpart.cp = p_dbl(lower = 0.001, upper = 0.1),
classif.rpart.minsplit = p_int(lower = 1, upper = 10),
subsample.frac = p_dbl(lower = 0.1, upper = 1, tags = "budget")
)
instance = TuningInstanceSingleCrit$new(
task = tsk("iris"),
learner = ll,
resampling = rsmp("holdout"),
measure = msr("classif.ce"),
terminator = trm("none"), # hyperband terminates itself
search_space = search_space
)
tuner = tnr("hyperband", eta = 3)
tuner$optimize(instance)
#> INFO [11:33:32.366] [bbotk] Starting to optimize 3 parameter(s) with '<TunerHyperband>' and '<TerminatorNone> [list()]'
#> INFO [11:33:32.407] [bbotk] Amount of brackets to be evaluated = 3,
#> INFO [11:33:32.413] [bbotk] Start evaluation of bracket 1
#> INFO [11:33:32.417] [bbotk] Training 9 configs with budget of 0.111111 for each
#> INFO [11:33:32.418] [bbotk] Evaluating 9 configuration(s)
#> INFO [11:33:32.561] [mlr3] Running benchmark with 9 resampling iterations
#> INFO [11:33:32.635] [mlr3] Applying learner 'subsample.classif.rpart' on task 'iris' (iter 1/1)
#> INFO [11:33:32.700] [mlr3] Applying learner 'subsample.classif.rpart' on task 'iris' (iter 1/1)
### OUTPUT DELETED FOR CLARITY ###
#> INFO [11:33:34.564] [bbotk] Finished optimizing after 22 evaluation(s)
#> INFO [11:33:34.565] [bbotk] Result:
#> INFO [11:33:34.566] [bbotk] classif.rpart.cp classif.rpart.minsplit subsample.frac learner_param_vals
#> INFO [11:33:34.566] [bbotk] 0.07348139 5 0.1111111 <list[6]>
#> INFO [11:33:34.566] [bbotk] x_domain classif.ce
#> INFO [11:33:34.566] [bbotk] <list[3]> 0.02
#> classif.rpart.cp classif.rpart.minsplit subsample.frac learner_param_vals
#> 1: 0.07348139 5 0.1111111 <list[6]>
#> x_domain classif.ce
#> 1: <list[3]> 0.02
instance$result
#> classif.rpart.cp classif.rpart.minsplit subsample.frac learner_param_vals
#> 1: 0.07348139 5 0.1111111 <list[6]>
#> x_domain classif.ce
#> 1: <list[3]> 0.02
由reprex 包于 2021-04-07 创建(v1.0.0)