Construct learners from a grid of parameters
learner_expand_grid(fun, args, names = TRUE, params = FALSE)
(function) A function that returns a learner.
(list) Parameters that generate a grid of parameters with
expand.list, where the set of parameters are then passed on to fun
.
(logical or character) If FALSE, then return a list without names. If TRUE, a named list is returned (see details).
(logical) If FALSE, then no information about the parameters
defined by args
are added to the names of the returned list.
list
lrs <- learner_expand_grid(
learner_xgboost,
list(formula = Sepal.Length ~ ., eta = c(0.2, 0.5, 0.3))
)
lrs # use info of constructed learner as names
#> $`xgboost reg:squarederror`
#> ────────── learner object ──────────
#> xgboost reg:squarederror
#>
#> Estimate arguments: max_depth=2, eta=0.2, nrounds=2, subsample=1, lambda=1, verbose=0, objective=reg:squarederror
#> Predict arguments:
#> Formula: Sepal.Length ~ . <environment: 0x55ff0bfcc990>
#>
#> $`xgboost reg:squarederror.1`
#> ────────── learner object ──────────
#> xgboost reg:squarederror
#>
#> Estimate arguments: max_depth=2, eta=0.5, nrounds=2, subsample=1, lambda=1, verbose=0, objective=reg:squarederror
#> Predict arguments:
#> Formula: Sepal.Length ~ . <environment: 0x55ff0bfcc990>
#>
#> $`xgboost reg:squarederror.2`
#> ────────── learner object ──────────
#> xgboost reg:squarederror
#>
#> Estimate arguments: max_depth=2, eta=0.3, nrounds=2, subsample=1, lambda=1, verbose=0, objective=reg:squarederror
#> Predict arguments:
#> Formula: Sepal.Length ~ . <environment: 0x55ff0bfcc990>
#>
lrs <- learner_expand_grid(
learner_xgboost,
list(formula = Sepal.Length ~ ., eta = c(0.2, 0.5, 0.3)),
names = "xgboost"
)
names(lrs) # use xgboost instead of info field for names
#> [1] "xgboost" "xgboost.1" "xgboost.2"
lrs <- learner_expand_grid(
learner_xgboost,
list(formula = Sepal.Length ~ ., eta = c(0.2, 0.5, 0.3)),
names = "xgboost",
params = TRUE
)
names(lrs) # also add parameters to names
#> [1] "xgboost:Sepal.Length ~ .:0.2" "xgboost:Sepal.Length ~ .:0.5"
#> [3] "xgboost:Sepal.Length ~ .:0.3"
lrs <- learner_expand_grid(
learner_xgboost,
list(formula = Sepal.Length ~ ., eta = c(0.2, 0.5, 0.3)),
names = FALSE
)
names(lrs) # unnamed list since names = FALSE
#> NULL