Skip to contents

The classbound package provides tools for exploring, visualizing, and comparing classification decision boundaries in R. It supports both two-dimensional data and high-dimensional data (via 2D slicing or linear projections), and works with native R classifiers, tidymodels workflows, and user-supplied models.

Details

Two main workflows

Interactive workflow: Launch explorapp() to start the built-in Shiny application. From there, you can import your own data, simulate datasets, draw data by hand, choose classifiers, adjust parameters, compare decision boundaries side-by-side, inspect probability surfaces, inject outliers, and export the results.

Programmatic workflow: Use the modular API directly:

model <- fit_model(data, formula, classifier)
model <- boundary_compute(model, feature_range, resolution = 100)
plot_boundary(model, obs_data = data, x_col = "x", y_col = "y", true_label = "class")

For a one-step wrapper, use classbound().

High-dimensional data

When a model is trained on more than two features, boundary_compute() supports two visualization strategies:

  • 2D Slice: two features are selected for the axes; all other numeric features are fixed at their median and categorical features at their mode.

  • Projection: a two-column orthonormal basis (e.g., PCA or a tour basis from the tourr package) defines a plane through the data center. The boundary grid is generated on this plane and inverse-projected back for prediction, so the regions are a planar section of the decision boundary; observations are projected onto the plane and faded by their distance from it.

Supported classifiers

Any classifier whose predict() method returns a vector or factor of class labels works automatically. Built-in adapters are provided for rpart, randomForest, PPtreeViz, PPtreeExt, and ppforest2. For classifiers that return complex objects (such as lists), use the predfun argument to extract class labels. Native tidymodels integration is available via boundary_workflow_set().

See also

Author

Maintainer: Vaibhav Manihar vaibhav.manihar@gmail.com

Authors: