bagger models

if (requireNamespace("baguette", quietly = TRUE)) {
  library(tidypredict)
  library(dplyr)
  eval_code <- TRUE
} else {
  eval_code <- FALSE
}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = eval_code
)

| Function |Works| |---------------------------------------------------------------|-----| |tidypredict_fit(), tidypredict_sql(), parse_model() | ✔ | |tidypredict_to_column() | ✔ | |tidypredict_test() | ✔ | |tidypredict_interval(), tidypredict_sql_interval() | ✗ | |parsnip | ✔ |

baguette::bagger() fits an ensemble of models on bootstrap samples of the training data. The "CART" base model, which fits rpart::rpart() trees, and the "C5.0" base model, which fits C50::C5.0() trees, are supported. tidypredict_fit() returns one nested case_when() per tree, so the size of the returned expression grows with times.

For regression models the fitted value is the mean of the individual tree predictions. For classification models the class probabilities of each tree are averaged, and the returned expression is the class with the largest average probability.

tidypredict_ functions

set.seed(100)
model <- baguette::bagger(mpg ~ wt + cyl + disp, data = mtcars, times = 5)

Classification

set.seed(100)
model <- baguette::bagger(Species ~ ., data = iris, times = 3)

tidypredict_test(model, iris)

C5.0 trees are only fit for classification, and are used by passing base_model = "C5.0".

set.seed(100)
model <- baguette::bagger(
  Species ~ .,
  data = iris,
  base_model = "C5.0",
  times = 3
)

tidypredict_test(model, iris)

parsnip

Models fit with parsnip::bag_tree() and the "rpart" or "C5.0" engine are supported as well.

library(parsnip)

set.seed(100)
model <- bag_tree(mode = "regression") %>%
  set_engine("rpart", times = 5) %>%
  fit(mpg ~ wt + cyl + disp, data = mtcars)

tidypredict_fit(model)


Try the tidypredict package in your browser

Any scripts or data that you put into this service are public.

tidypredict documentation built on Oct. 18, 2026, 5:06 p.m.