viz_decision_boundary: Draw Decision boundary for Classification model

Description Usage Arguments Value Examples

View source: R/viz_decision_boundary.R

Description

This function is mostly useful in an educational setting. Can only be used with trained workflow objects with 2 numeric predictor variables.

Usage

1
viz_decision_boundary(x, new_data, resolution = 100, expand = 0.1)

Arguments

x

trained 'workflows::workflow' object.

new_data

A data frame or tibble for whom the preprocessing will be applied.

resolution

Number of squared in grid. Defaults to 100.

expand

Expansion rate. Defaults to 0.1. This means that the width and height of the shaded area is 10 data.

The chart have been minimally modified to allow for easier styling.

Value

'ggplot2::ggplot' object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(parsnip)
library(workflows)
svm_spec <- svm_rbf() %>%
  set_mode("classification") %>%
  set_engine("kernlab")

svm_fit <- workflow() %>%
  add_formula(Species ~ Petal.Length + Petal.Width) %>%
  add_model(svm_spec) %>%
  fit(iris)

viz_decision_boundary(svm_fit, iris)

viz_decision_boundary(svm_fit, iris, resolution = 20)

viz_decision_boundary(svm_fit, iris, expand = 1)

svm_multi_fit <- workflow() %>%
  add_formula(class ~ umap_1 + umap_2) %>%
  add_model(svm_spec) %>%
  fit(mnist_sample)

viz_decision_boundary(svm_multi_fit, mnist_sample)

EmilHvitfeldt/horus documentation built on June 12, 2021, 7 p.m.