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, wherexis a numeric data frame of predictors andya 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.
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
