2

有没有办法在 R 包中设置特定的参数值paradox?假设我为随机森林方法进行超参数调整,我想测试mtry = c(2, 3, 7, 8)min.node.size = c(2, 5, 7),即 4 x 3 网格,值之间的距离不相等。

目前,我必须进行大型 7 x 6 网格搜索以包含这些值,测试我不感兴趣的组合:

tuner_params = ParamSet$new(list(
  ParamInt$new("mtry", lower = 2, upper = 7),
  ParamInt$new("min.node.size", lower = 2, upper = 6)
))

generate_design_grid(tuner_params, param_resolutions = c(mtry = 7, min.node.size = 5))
4

1 回答 1

4

克服这个问题的一种方法是不使用网格搜索,而是使用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 个点。

于 2020-07-07T14:01:24.173 回答