-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathex2_tune.R
29 lines (20 loc) · 889 Bytes
/
ex2_tune.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
### Basic hyperparameter comparison / tuning
library(mlr)
# we will compare values of k know for the data set
lrn = makeLearner("classif.svm")
# cross-validation, no need to pregenerate now.
# as this is sensible, tuneParams will do this for us automatically
rdesc = makeResampleDesc("CV", iters = 3L)
# Description of our parameter space we want to grid-search over
par.set = makeParamSet(
makeNumericParam("cost", lower = -15, upper = 15, trafo = function(x) 2^x),
makeNumericParam("gamma", lower = -15, upper = 15, trafo = function(x) 2^x)
)
# run it
# (actually, mlr supports many other tuner, so we need to select the tuner via a control object here)
ctrl = makeTuneControlGrid(resolution = 5L)
res = tuneParams(lrn, sonar.task, rdesc, par.set = par.set, control = ctrl)
# access full info of result
print(res)
print(names(res))
print(head(as.data.frame(res$opt.path)))