fit_best_learner {postcard} | R Documentation |
Find the best learner in terms of RMSE among specified learners using cross validation
Description
Find the best learner in terms of RMSE among specified learners using cross validation
Usage
fit_best_learner(
preproc,
data,
cv_folds = 5,
learners = default_learners(),
verbose = options::opt("verbose")
)
Arguments
preproc |
A list (preferably named) with preprocessing objects:
formulas, recipes, or |
data |
A data frame. |
cv_folds |
a |
learners |
a |
verbose |
|
Details
Ensure data compatibility with the learners.
Value
a trained workflow
See Also
See rctglm_with_prognosticscore()
for a function that utilises this
function to perform prognostic covariate adjustment.
Examples
# Generate some synthetic 2-armed RCT data along with historical controls
n <- 100
dat_rct <- glm_data(
Y ~ 1+2*x1+3*a,
x1 = rnorm(n, 2),
a = rbinom (n, 1, .5),
family = gaussian()
)
dat_hist <- glm_data(
Y ~ 1+2*x1,
x1 = rnorm(n, 2),
family = gaussian()
)
# Fit a learner to the historical control data
learners <- list(
mars = list(
model = parsnip::set_engine(
parsnip::mars(
mode = "regression", prod_degree = 3
),
"earth"
)
)
)
fit <- fit_best_learner(
preproc = list(mod = Y ~ .),
data = dat_hist,
learners = learners
)
# Use it fx. to predict the "control outcome" in the 2-armed RCT
predict(fit, new_data = dat_rct)