Skip to contents

A high-level unified wrapper to fit a model, compute its 2D decision boundary, and plot the results in a single step.

Usage

classbound(
  data,
  formula,
  classifier,
  interface = c("formula", "matrix", "custom"),
  projection = NULL,
  fit_args = list(),
  predict_args = list(),
  predfun = NULL,
  resolution = 100,
  ...
)

Arguments

data

A data frame containing the full training dataset. The specific variables used for modeling and plotting are strictly determined by the formula.

formula

A formula specifying the response and predictors.

classifier

The classification function to use (e.g., rpart::rpart, e1071::svm). This works with any R package classification algorithm. If the classifier uses a non-standard API, you can adapt it via the predfun argument.

interface

A string specifying how to invoke the classifier: "formula", "matrix", or "custom".

projection

An optional list (e.g., list(basis=..., center=..., scale=...)) specifying a 2D projection for high-dimensional data.

fit_args

A named list of additional arguments passed to the classifier during fitting.

predict_args

A named list of additional arguments passed to predict() during boundary computation.

predfun

A custom function to generate predictions for non-standard models.

resolution

An integer specifying the grid resolution for the decision boundary.

...

Additional arguments passed to plot_boundary.

Value

A ggplot object visualizing the 2D decision boundary and original observations.

Examples

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

# Quick 2D boundary visualization for an SVM
classbound(peng_data, species ~ bill_length_mm + bill_depth_mm, e1071::svm)

# }