Learn R Programming

mlr (version 1.1-18)

makeTuneWrapper: Fuse learner with tuning.

Description

Fuses a base learner with a search strategy to select its hyperparameters. Creates a learner object, which can be used like any other learner object, but which internally uses tune. If the train function is called on it, the search strategy and resampling are invoked to select an optimal set of hyperparameter values. Finally, a model is fitted on the complete training data with these optimal hyperparameters and returned. See tuneParams for more details.

Usage

makeTuneWrapper(learner, resampling, measures, par.set,
    control, show.info = TRUE)

Arguments

Value

[Learner].

Details

After training, the optimal hyperparameters (and other related information) can be retrieved with getTuneResult.

Examples

Run this code
task = makeClassifTask(data=iris, target="Species")
lrn = makeLearner("classif.ksvm")
# stupid mini grid
ps = makeParamSet(
  makeDiscreteParam("C", values = 1:2),
  makeDiscreteParam("sigma", values = 1:2)
)
ctrl = makeTuneControlGrid()
inner = makeResampleDesc("Holdout")
outer = makeResampleDesc("CV", iters = 2)
lrn = makeTuneWrapper(lrn, resampling = inner, par.set = ps, control = ctrl)
mod = train(lrn, task)
print(getTuneResult(mod))
# nested resampling for evaluation
# we also extract tuned hyper pars in each iteration
r = resample(lrn, task, outer, extract = function(model) {
  getTuneResult(model)$x
})
print(r$extract)

Run the code above in your browser using DataLab