Learn R Programming

SuperLearner (version 2.0-22)

create.Learner: Factory for learner wrappers

Description

Create custom learners and/or a sequence of learners with hyperparameter combinations defined over a grid.

Usage

create.Learner(base_learner, params = list(), tune = list(),
  env = parent.frame(), name_prefix = base_learner, detailed_names = F,
  verbose = F)

Arguments

base_learner

Character string of the learner function that will be customized.

params

List with parameters to customize.

tune

List of hyperparameter settings that will define custom learners.

env

Environment in which to create the functions. Defaults to the current environment (e.g. often the global environment).

name_prefix

The prefix string for the name of each function that is generated.

detailed_names

Set to T to have the function names include the parameter configurations.

verbose

Display extra details.

Value

Returns a list with expanded tuneGrid and the names of the created functions.

Examples

Run this code
# NOT RUN {
# Create a randomForest learner with ntree set to 1000 rather than the
# default of 500.
create_rf = create.Learner("SL.randomForest", list(ntree = 1000))
create_rf
sl = SuperLearner(Y = Y, X = X, SL.library = create_rf$names, family = binomial())
sl
# Clean up global environment.
rm(list = create_rf$names)
# Create a randomForest learner that optimizes over mtry
create_rf = create.Learner("SL.randomForest",
                     tune = list(mtry = round(c(1, sqrt(ncol(X)), ncol(X)))))
create_rf
sl = SuperLearner(Y = Y, X = X, SL.library = create_rf$names, family = binomial())
sl
# Clean up global environment.
rm(list = create_rf$names)

# Optimize elastic net over alpha, with a custom environment and detailed names.
learners = new.env()
create_enet = create.Learner("SL.glmnet", env = learners, detailed_names = T,
                           tune = list(alpha = seq(0, 1, length.out=5)))
create_enet
# List the environment to review what functions were created.
ls(learners)
# We can simply list the environment to specify the library.
sl = SuperLearner(Y = Y, X = X, SL.library = ls(learners), family = binomial(), env = learners)
sl
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab