create.Learner: Factory for learner wrappers

View source: R/create.Learner.R

create.LearnerR Documentation

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

## 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

## End(Not run)


ecpolley/SuperLearner documentation built on Feb. 21, 2024, 11:38 p.m.