克服这个问题的一种方法是不使用网格搜索,而是使用TunerDesignPoints。
参见示例:
library(paradox)
library(mlr3)
library(mlr3tuning)
library(mlr3learners)
library(data.table)
tuner_params = ParamSet$new(list(
ParamInt$new("mtry", lower = 2, upper = 8),
ParamInt$new("min.node.size", lower = 2, upper = 7)
))
指定自定义设计点:
design = data.table(expand.grid(mtry = c(2, 3, 7, 8),
min.node.size = c(2, 5, 7)))
tuner = tnr("design_points", design = design)
sonar_task = tsk("sonar")
r_lrn = lrn("classif.ranger", predict_type = "prob")
instance = TuningInstance$new(
task = sonar_task,
learner = r_lrn,
resampling = rsmp("cv", folds = 3),
measures = msr("classif.acc"),
param_set = tuner_params,
terminator = term("none")) #no terminator since you want all design points evaluated
tuner$tune(instance)
instance$archive()
#输出
nr batch_nr resample_result task_id learner_id resampling_id iters params tune_x warnings errors classif.acc
1: 1 1 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8462388
2: 2 2 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8366460
3: 3 3 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8317460
4: 4 4 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8269151
5: 5 5 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8366460
6: 6 6 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8173913
7: 7 7 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8221532
8: 8 8 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8124914
9: 9 9 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8415459
10: 10 10 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8173223
11: 11 11 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8221532
12: 12 12 <ResampleResult> sonar classif.ranger cv 3 <list> <list> 0 0 0.8221532
像我们在设计网格中指定的那样评估了 12 个点。