fit_predict: Fit a Learner and Predict New Data

View source: R/fit_predict.R

fit_predictR Documentation

Fit a Learner and Predict New Data

Description

Train one regression model on x and y with an algorithm named as a string, then return its predictions for newdata, their standard errors when the algorithm provides them, and the training R-squared.

Usage

fit_predict(
  x,
  y,
  newdata,
  algorithm,
  params = NULL,
  se = FALSE,
  verbosity = 0L
)

Arguments

x

data.frame: Features, one column per predictor.

y

Numeric: Outcome, one value per row of x.

newdata

data.frame: Features to predict, with the columns of x.

algorithm

Character: Supervised learning algorithm name, matched case-insensitively, e.g. "LINAD", "CART", "LightGBM". See available_supervised().

params

Optional Named list: Arguments to the algorithm's setup function, e.g. list(max_leaves = 8) for setup_LINAD(). NULL uses the algorithm's defaults.

se

Logical: If TRUE, compute standard errors of the fit for newdata.

verbosity

Integer: Verbosity level.

Details

This is the bridge behind fit = "<algorithm>" in rtemis.draw::draw_scatter(), rtemis.draw::draw_fit() and rtemis.draw::draw_scatter3d(), which need a fitted curve or surface from a name alone. For full control over training, use train().

Value

Named list: fitted (Numeric predictions for newdata), se (Numeric standard errors, or NULL when se = FALSE or the algorithm has none), rsq (Numeric training R-squared), and algorithm (Character canonical algorithm name).

Author(s)

EDG

Examples

fit <- fit_predict(
  mtcars["wt"], mtcars[["mpg"]],
  newdata = data.frame(wt = c(2, 3, 4)),
  algorithm = "GLM",
  se = TRUE
)
fit[["fitted"]]
fit_predict(
  mtcars["wt"], mtcars[["mpg"]],
  newdata = data.frame(wt = c(2, 3, 4)),
  algorithm = "LINAD",
  params = list(max_leaves = 2)
)[["fitted"]]

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.