How natydasilva/classbound works
classbound is an R package built around a small pipeline for classification-boundary exploration: prepare 2D data, fit a supported classifier, compute predictions on a grid, and visualize the resulting decision surface.
1. Primary user-facing API
The package centers on a few exported functions: fit_model(), predict_model(), boundary_compute(), plot_boundary(), and preprocess_data(). These form the main architectural path from raw data to boundary plot. The README’s example shows the intended flow clearly: fit a model, generate a prediction grid over a feature range, then plot that grid against the original observations.
2. Model abstraction layer
The codebase is organized around a common adapter interface in R/adapter_interface.R, with concrete adapters for multiple classification backends:
- rpart
- randomForest
- pptree
- PPforest
- PPtreeViz
This is the key boundary in the system: the rest of the package works against a unified model contract rather than handling each learner separately.
3. Fit pipeline
fit_model() is the entry point for model training. It likely delegates to the appropriate adapter based on the method argument, creating a fitted model object in a common wrapper format. That wrapper is what later functions consume, which keeps model-specific details isolated inside adapter files.
4. Prediction pipeline
predict_model() is the second half of the abstraction. It provides a method-agnostic way to generate class predictions from fitted model objects. This is important because boundary computation depends on prediction being consistent across all supported learners.
5. Decision-boundary computation
boundary_compute() is the transformation from a fitted classifier to a visualizable surface. It takes a 2D feature range and a resolution, constructs a grid of points over that space, and runs predictions across the grid. The output is a table-like boundary dataset suitable for plotting, rather than a model object or a plot object.
6. Visualization layer
plot_boundary() is responsible for rendering the computed boundary together with the original observations. The architecture here separates computation from presentation: boundary generation is done first, then a dedicated visualization function converts it into a figure. The README indicates the plot includes both the predicted surface and the true labels from the observed data.
7. Data preprocessing and compatibility
preprocessing.R suggests a normalization/validation step that adapts user data into the form required by the model and boundary pipeline. This is where the package likely handles class labels, feature selection, and consistent input formatting so that different backends can be used interchangeably.
8. Interactive exploration subsystem
app.R and the exported explorapp() documentation indicate a Shiny-based interactive app. This app sits on top of the same core pipeline, likely letting users change model type, ranges, or preprocessing settings and immediately see how the boundary changes. It is an interface layer, not a separate computational engine.
9. Synthetic and example data
simulation.R and data69_1.R/data/data69_1.rda provide built-in data and generated examples. These support reproducible demos, tests, and documentation. They are not part of the runtime pipeline, but they matter because they exercise the visualization and model adapters across known scenarios.
10. Package testing and compatibility focus
The test suite is broad and explicitly names each backend (test-rpart, test-randomForest, test-pptree, test-PPforest, test-PPtreeViz), plus pipeline, boundary, preprocessing, and visualization tests. That indicates the main architectural risk the package manages is cross-model consistency: the same public API must behave correctly for every adapter.
11. Documentation and developer tooling
The repository is a standard R package with DESCRIPTION, NAMESPACE, man/, vignettes/, and GitHub Actions for R-CMD-check and pkgdown. These are supporting layers around the core architecture: they ensure the package API is documented, the examples are reproducible, and the adapter/pipeline contract stays stable.
12. Overall data flow
The end-to-end flow is: user data → preprocessing → adapter-based model fitting → adapter-based prediction on a grid → boundary dataset → boundary visualization or Shiny exploration. The strongest architectural boundary is between the model-specific adapters and the generic boundary/plotting pipeline.
Main entry points: adapter_interface.R Adapter API · testthat Tests · fit_model.R Fit model · app.R Exploration app
Components 18
Core pipeline
User-facing data-to-boundary flow
- Preprocess · Validates and reshapes input data for the boundary pipeline
R/preprocessing.R - Fit model · Trains a classifier through the adapter layer
R/fit_model.R - Predict model · Generates method-agnostic class predictions from fitted models
R/predict_model.R - Boundary grid · Builds a 2D prediction grid and computes decision surface values
R/boundary_compute.R - Plot boundary · Renders the decision surface with the observed data
R/visualization.R
Model adapters
Common classifier contract and backend implementations
- Adapter API · Shared interface used by all supported classifier backends
R/adapter_interface.R - rpart · Backend adapter for rpart classification trees
R/rpart_adapter.R - randomForest · Backend adapter for randomForest classification models
R/randomForest_adapter.R - pptree · Backend adapter for pptree models
R/pptree_adapter.R - PPforest · Backend adapter for PPforest models
R/PPforest_adapter.R - PPtreeViz · Backend adapter for PPtreeViz models
R/PPtreeViz_adapter.R
Support
Interactive app, examples, docs, and tests
- Exploration app · Interactive front end for exploring boundaries and model settings
R/app.R - Simulation · Generates synthetic data used for demos and exploration
R/simulation.R - Example data · Packaged example dataset for documentation and testing
data/data69_1.rda - Tests · Verifies pipeline behavior, preprocessing, boundary logic, and backend compatibility
tests/testthat - Package docs · Package metadata, manual pages, README, and vignettes
DESCRIPTION - Site config · Documentation site and package publishing configuration
_pkgdown.yml - CI workflows · Automated checks and site build workflows
.github/workflows/R-CMD-check.yaml
Connections 23
- Preprocess → Fit model: prepared data · Cleaned data is passed into training
- Fit model → Adapter API: uses · Training goes through the common adapter contract
- Adapter API → rpart: implements · Concrete backend implementation
- Adapter API → randomForest: implements · Concrete backend implementation
- Adapter API → pptree: implements · Concrete backend implementation
- Adapter API → PPforest: implements · Concrete backend implementation
- Adapter API → PPtreeViz: implements · Concrete backend implementation
- Fit model → Predict model: fitted model · Trained models are consumed by prediction
- Predict model → Boundary grid: grid predictions · Boundary computation depends on consistent prediction across backends
- Boundary grid → Plot boundary: boundary data · Computed surface is rendered by the plotting layer
- Exploration app → Preprocess: uses · Interactive exploration starts from the same preprocessing step
- Exploration app → Fit model: uses · The app can train supported models on demand
- Exploration app → Boundary grid: uses · The app updates boundary surfaces interactively
- Exploration app → Plot boundary: uses · The app displays the resulting plot
- Simulation → Example data: example inputs · Synthetic and packaged data support reproducible examples
- Tests → Preprocess: covers · Validates preprocessing behavior
- Tests → Boundary grid: covers · Validates boundary generation
- Tests → Plot boundary: covers · Validates visualization output
- Tests → Adapter API: covers · Checks cross-backend consistency
- Package docs → Fit model: documents · Manual pages and README describe the main API
- Package docs → Plot boundary: documents · Documentation includes the plotting workflow
- Site config → Package docs: publishes · Site configuration supports package documentation publishing
- CI workflows → Tests: runs · CI executes the test suite and package checks