if (rlang::is_installed("mboost")) { library(tidypredict) library(mboost) library(dplyr) eval_code <- TRUE } else { eval_code <- FALSE } knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = eval_code ) set.seed(1)
| Function |Works|
|---------------------------------------------------------------|-----|
|tidypredict_fit(), tidypredict_sql(), parse_model() | ✔ |
|tidypredict_to_column() | ✔ |
|tidypredict_test() | ✔ |
|tidypredict_interval(), tidypredict_sql_interval() | ✗ |
|parsnip | ✗ |
mboost::blackboost() boosts regression trees. Each boosting iteration
contributes one tree, shrunk by the learning rate nu, and the contributions
are added to the model's offset.
library(mboost) library(dplyr) library(tidypredict) model <- blackboost( mpg ~ wt + cyl, data = mtcars, control = boost_control(mstop = 10) )
The parser walks the partykit tree behind every boosting iteration and turns
it into one nested dplyr::case_when() statement. The learning rate and the
offset are folded into the result.
pm <- parse_model(model) str(pm, 2)
The parsed model is transformed into a dplyr, a.k.a. Tidy Eval, formula.
tidypredict_fit(model)
From there, the Tidy Eval formula can be used anywhere it can be evaluated.
tidypredict provides three paths:
dplyr, mutate(mtcars, !! tidypredict_fit(model))tidypredict_to_column(model) to add it to a piped command settidypredict_sql(model, con) to retrieve the SQL statementmtcars %>% tidypredict_to_column(model) %>% glimpse()
tidypredict_test(model, df = mtcars)
blackboost() handles factors natively, and the generated formula uses %in%
for the resulting splits.
df <- transform(mtcars, cyl = factor(cyl)) model_cat <- blackboost( mpg ~ wt + cyl, data = df, control = boost_control(mstop = 10) ) tidypredict_test(model_cat, df = df)
Gaussian() family is supported. Other families apply a response
function that cannot be expressed as a single formula.parsnip engine for blackboost().Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.