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.
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". Seeavailable_supervised().- params
Optional Named list: Arguments to the algorithm's setup function, e.g.
list(max_leaves = 8)forsetup_LINAD().NULLuses the algorithm's defaults.- se
Logical: If TRUE, compute standard errors of the fit for
newdata.- verbosity
Integer: Verbosity level.
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).
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().
Examples
fit <- fit_predict(
mtcars["wt"], mtcars[["mpg"]],
newdata = data.frame(wt = c(2, 3, 4)),
algorithm = "GLM",
se = TRUE
)
fit[["fitted"]]#> [1] 26.59618 21.25171 15.90724fit_predict(
mtcars["wt"], mtcars[["mpg"]],
newdata = data.frame(wt = c(2, 3, 4)),
algorithm = "LINAD",
params = list(max_leaves = 2)
)[["fitted"]]#> [1] 26.37791 21.29574 16.04946