Description Usage Arguments Value Note See Also Examples
View source: R/ModelMultiplexer.R
Combines multiple base learners by dispatching
on the hyperparameter “selected.learner” to a specific model class.
This allows to tune not only the model class (SVM, random forest, etc) but also
their hyperparameters in one go. Combine this with tuneParams
and
makeTuneControlIrace
for a very powerful approach, see example below.
The parameter set is the union of all (unique) base learners. In order to avoid name clashes all parameter names are prefixed with the base learner id, i.e. “[learner.id].[parameter.name]”.
The predict.type of the Multiplexer is inherited from the predict.type of the base learners.
The getter getLearnerProperties
returns the properties of the
selected base learner.
1 | makeModelMultiplexer(base.learners)
|
base.learners |
[ |
[ModelMultiplexer
]. A Learner
specialized as ModelMultiplexer
.
Note that logging output during tuning is somewhat shortened to make it more readable. I.e., the artificial prefix before parameter names is suppressed.
Other multiplexer: makeModelMultiplexerParamSet
Other tune: TuneControl
,
getNestedTuneResultsOptPathDf
,
getNestedTuneResultsX
,
getTuneResult
,
makeModelMultiplexerParamSet
,
makeTuneControlCMAES
,
makeTuneControlDesign
,
makeTuneControlGenSA
,
makeTuneControlGrid
,
makeTuneControlIrace
,
makeTuneControlMBO
,
makeTuneControlRandom
,
makeTuneWrapper
, tuneParams
,
tuneThreshold
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 36 37 38 39 40 41 42 | library(BBmisc)
bls = list(
makeLearner("classif.ksvm"),
makeLearner("classif.randomForest")
)
lrn = makeModelMultiplexer(bls)
# simple way to contruct param set for tuning
# parameter names are prefixed automatically and the 'requires'
# element is set, too, to make all paramaters subordinate to 'selected.learner'
ps = makeModelMultiplexerParamSet(lrn,
makeNumericParam("sigma", lower = -10, upper = 10, trafo = function(x) 2^x),
makeIntegerParam("ntree", lower = 1L, upper = 500L)
)
print(ps)
rdesc = makeResampleDesc("CV", iters = 2L)
# to save some time we use random search. but you probably want something like this:
# ctrl = makeTuneControlIrace(maxExperiments = 500L)
ctrl = makeTuneControlRandom(maxit = 10L)
res = tuneParams(lrn, iris.task, rdesc, par.set = ps, control = ctrl)
print(res)
print(head(as.data.frame(res$opt.path)))
# more unique and reliable way to construct the param set
ps = makeModelMultiplexerParamSet(lrn,
classif.ksvm = makeParamSet(
makeNumericParam("sigma", lower = -10, upper = 10, trafo = function(x) 2^x)
),
classif.randomForest = makeParamSet(
makeIntegerParam("ntree", lower = 1L, upper = 500L)
)
)
# this is how you would construct the param set manually, works too
ps = makeParamSet(
makeDiscreteParam("selected.learner", values = extractSubList(bls, "id")),
makeNumericParam("classif.ksvm.sigma", lower = -10, upper = 10, trafo = function(x) 2^x,
requires = quote(selected.learner == "classif.ksvm")),
makeIntegerParam("classif.randomForest.ntree", lower = 1L, upper = 500L,
requires = quote(selected.learner == "classif.randomForst"))
)
# all three ps-objects are exactly the same internally.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.