-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathex3_tune_irace.R
37 lines (27 loc) · 1.22 KB
/
ex3_tune_irace.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
### Complex hyperparameter tuning with wrapper and nested resampling
library(mlr)
library(mlbench)
# param set for an svm, multiple kernel, dependent parameters and trafos
lrn = makeLearner("classif.svm")
ps = makeParamSet(
makeDiscreteParam("kernel", values = c("polynomial", "radial")),
makeNumericParam("cost", lower = -15, upper = 15, trafo = function(x) 2^x),
makeNumericParam("gamma", lower = -15, upper = 15, trafo = function(x) 2^x,
requires = expression(kernel == "radial")),
makeIntegerParam("degree", lower = 1, upper = 5,
requires = expression(kernel == "polynomial"))
)
# we can use irace or a simple random search here
# ctrl = makeTuneControlIrace(maxExperiments = 100L)
ctrl = makeTuneControlRandom(maxit = 20)
# this adds the tuning to the learner, we use holdout on inner resampling
inner = makeResampleDesc(method = "Holdout")
lrn2 = makeTuneWrapper(lrn, inner, par.set = ps, control = ctrl, measures = mmce)
# now run everything, we use CV with 2 folds on the outer loop
outer = makeResampleDesc(method = "CV", iters = 2)
r = resample(lrn2, sonar.task, outer, extract = getTuneResult)
print(r)
# lets look at some results from the outer iterations
r$extract[[1]]$x
r$extract[[1]]$y
r$extract[[1]]$opt.path