如何在 `paradox` 中设置特定值?
How to set specific values in `paradox`?
有没有办法在 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))
克服这个问题的一种方法是不使用网格搜索,而是 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()
#output
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 分。
有没有办法在 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))
克服这个问题的一种方法是不使用网格搜索,而是 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()
#output
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 分。