View source: R/fit_best_learner.R
fit_best_learner | R Documentation |
Find the best learner in terms of RMSE among specified learners using cross validation
fit_best_learner(
preproc,
data,
cv_folds = 5,
learners = default_learners(),
verbose = options::opt("verbose")
)
preproc |
A list (preferably named) with preprocessing objects:
formulas, recipes, or |
data |
A data frame. |
cv_folds |
a |
learners |
a |
verbose |
|
Ensure data compatibility with the learners.
a trained workflow
See rctglm_with_prognosticscore()
for a function that utilises this
function to perform prognostic covariate adjustment.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.