as_classbound: Convert a fitted model into a classbound object

View source: R/as_classbound.R

as_classboundR Documentation

Convert a fitted model into a classbound object

Description

Wraps a pre-fitted model in a classbound object, adding the feature metadata (names, types, ranges, imputation values) required by boundary_compute() and plot_boundary(). This is the entry point for "bring your own model" (BYO) workflows, including native tidymodels workflows and parsnip model fits.

Usage

as_classbound(model, data, response = NULL, ...)

Arguments

model

A fitted model object. For tidymodels objects, must be a trained workflow or model_fit (not a model specification).

data

A data frame of the training data. Used only to extract feature metadata; the data is not passed through preprocess_data(). Must contain all features that the model was trained on.

response

Optional string naming the response column in data. If provided, this column is excluded from feature metadata and its levels are stored as class levels. If NULL, class levels will be NULL in the returned object.

...

Additional arguments passed to methods.

Details

Unlike fit_model(), as_classbound() does not refit the model or call preprocess_data(). Feature metadata is extracted solely from the data argument, which should be the same data used to fit the model. If the model was fitted on scaled or transformed data, ensure data reflects that transformation.

as_classbound() dispatches on the class of model:

  • Default: wraps any fitted model object (e.g., rpart, lda).

  • workflow: requires the workflow to already be trained (via fit()). Use boundary_workflow_set() to train and wrap an entire workflow set at once.

  • model_fit: wraps a fitted parsnip model.

Value

A classbound object ready for use with boundary_compute() and plot_boundary().

See Also

fit_model(), boundary_workflow_set(), boundary_compute()

Examples


library(palmerpenguins)
data(penguins)
peng_data <- na.omit(penguins[, c("species", "bill_length_mm", "bill_depth_mm")])

# Wrap any pre-fitted model
raw_model <- rpart::rpart(species ~ ., data = peng_data)
cb_model <- as_classbound(raw_model, data = peng_data, response = "species")

# Tidymodels: wrap a fitted workflow
# (boundary_workflow_set() does this automatically for entire workflow sets)


classbound documentation built on Sept. 30, 2026, 5:13 p.m.