Skip to contents

Adds an algorithm to the learner registry so that train_model() can select it by name. Keeping learners behind a registry is what allows the package to delegate to established implementations rather than reimplement them.

Usage

register_learner(name, fit, predict, requires = character(), description = "")

Arguments

name

Name used to select the learner.

fit

A function function(x, y, ...) returning a fitted model, where x is a numeric data frame of predictors and y a numeric response.

predict

A function function(object, newx, ...) returning a numeric vector of predictions.

requires

Character vector of packages the learner needs.

description

A one-line human description.

Value

Invisibly, the registered name.

Examples

register_learner("mean_only",
                 fit = function(x, y, ...) mean(y),
                 predict = function(object, newx, ...) {
                     rep(object, nrow(newx))
                 })
"mean_only" %in% list_learners()$name
#> [1] TRUE