View source: R/decision_boundary.R
| decision_boundary | R Documentation |
Adds the decision boundary from a classification model (binary or multiclass) to an existing scatterplot.
decision_boundary(model, train, y, x1, x2, pfun, grid.resolution = 100, ...) ## Default S3 method: decision_boundary( model, train, y, x1, x2, pfun = NULL, grid.resolution = 100, ... )
model |
The associated model object. |
train |
Data frame of training observations. |
y |
Character string giving the name of the outcome variable in
|
x1 |
Character string giving the name of the predictor in |
x2 |
Character string giving the name of the predictor in |
pfun |
Optional prediction wrapper that returns a vector of predicted
class labels. It must have exactly two arguments: |
grid.resolution |
Integer specifying the resolution of the contour plot.
Default is |
... |
Additional optional arguments to be passed on to
|
No return value, only called for side effects; in this case, a contour displaying the decision boundary of a classifier is added to an existing scatterplot.
Based on a function written by Michael Hahsler; see https://michael.hahsler.net/SMU/EMIS7332/R/viz_classifier.html.
## Not run:
library(mlbench)
library(rpart)
library(treemisc)
# Generate training data from the twonorm benchmark problem
set.seed(1050) # for reproducibility
trn <- as.data.frame(mlbench.twonorm(500, d = 2))
# Fit a default classification tree
tree <- rpart(classes ~ ., data = trn)
# Scatterplot of training data
palette("Okabe-Ito")
plot(x.2 ~ x.1, data = trn, col = as.integer(trn$classes) + 1,
xlab = expression(x[1]), ylab = expression(x[2]))
palette("default")
# Add a decision boundary
decision_boundary(tree, train = trn, y = "y", x1 = "x.1", x2 = "x.2")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.