Get tuning parameters from a learner of the caret R-package.
Source:R/getCaretParamSet.R
getCaretParamSet.Rd
Constructs a grid of tuning parameters from a learner of the caret
R-package. These values are then converted into a list of non-tunable
parameters (par.vals
) and a tunable
ParamHelpers::ParamSet (par.set
), which can be used by
tuneParams for tuning the learner. Numerical parameters will
either be specified by their lower and upper bounds or they will be
discretized into specific values.
Arguments
- learner
(
character(1)
)
The name of the learner fromcaret
(cf. https://topepo.github.io/caret/available-models.html). Note that the names incaret
often differ from the ones inmlr
.- length
(
integer(1)
)
A length / precision parameter which is used bycaret
for generating the grid of tuning parameters.caret
generates either as many values per tuning parameter / dimension as defined bylength
or only a single value (in case of non-tunablepar.vals
).- task
(Task)
Learning task, which might be requested for creating the tuning grid.- discretize
(
logical(1)
)
Should the numerical parameters be discretized? Alternatively, they will be defined by their lower and upper bounds. The default isTRUE
.
Value
(list(2)
). A list of parameters:
par.vals
contains a list of all constant tuning parameterspar.set
is a ParamHelpers::ParamSet, containing all the configurable tuning parameters
Examples
if (requireNamespace("caret") && requireNamespace("mlbench")) {
library(caret)
classifTask = makeClassifTask(data = iris, target = "Species")
# (1) classification (random forest) with discretized parameters
getCaretParamSet("rf", length = 9L, task = classifTask, discretize = TRUE)
# (2) regression (gradient boosting machine) without discretized parameters
library(mlbench)
data(BostonHousing)
regrTask = makeRegrTask(data = BostonHousing, target = "medv")
getCaretParamSet("gbm", length = 9L, task = regrTask, discretize = FALSE)
}
#> Loading required namespace: caret
#> Loading required package: ggplot2
#> Loading required package: lattice
#>
#> Attaching package: ‘caret’
#> The following object is masked from ‘package:mlr’:
#>
#> train
#> note: only 3 unique complexity parameters in default grid. Truncating the grid to 3 .
#>
#> $par.vals
#> $par.vals$shrinkage
#> [1] 0.1
#>
#> $par.vals$n.minobsinnode
#> [1] 10
#>
#>
#> $par.set
#> Type len Def Constr Req Tunable Trafo
#> interaction.depth integer - - 1 to 9 - TRUE -
#> n.trees numeric - - 50 to 450 - TRUE -
#>