plot.nb2: Plot Naive Bayes Models

Description Usage Arguments See Also Examples

Description

Plot Naive Bayes Models

Usage

1
2
3
## S3 method for class 'nb2'
plot(x, xlim, ylim, features, sdevs = 2, gridsize, data,
  class.name = "class", ..., gg = TRUE, psize = 2.5)

Arguments

x

[nb2]
A Naive Bayes Model

xlim, ylim

[numeric(2)]

features

[numeric(2) | character(2)]
If missing, the first two features are plotted.

sdevs

[numeric(1)]
If missing(xlim) & missing(ylim): How many standard deviations from the mean in x and y direction.

gridsize

[numeric(1)]
Size of grid to be predicted and plotted.

data

[list | data.frame]
List with elements "x" and "class" or data.frame (then see argument class.name).

class.name

[character]
If data is data.frame, then give the class' column name here. Default: "class".

...

Currently ignored.

gg

[logical]
Use ggplot2 for plotting? Highly recommended!

psize

[numeric]
Point size for geom_point.

See Also

nb2, update.nb2, print.nb2, predict.nb2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
mod <- nb2(iris[, 1:4], iris[, 5])
plot(mod, features = 2:3, xlim = c(1.5, 4.5), ylim = c(0.5, 7.5),
     gridsize = 75, gg = FALSE)
points(iris[, 2:3], col = iris[, 5], pch = 4, lwd = 3)

require(ggplot2)
mod1 <- nb2(iris[, 1:4], iris[, 5])
preds <- predict(mod1, iris[, c(1, 3)])
iris2 <- cbind(iris, err = (preds != iris$Species))
plot(mod1, features = c(1, 3), xlim = c(4, 8), ylim = c(0, 8)) +
  geom_point(data = subset(iris2, iris2$err),
             aes(x = Sepal.Length, y = Petal.Length, shape = Species),
             size = 3.5, col = "white", show.legend = FALSE) +
  geom_point(aes(x = Sepal.Length, y = Petal.Length, shape = Species),
             data = iris2, size = 2) +
  guides(colour = FALSE, shape = FALSE)

discParam <- list(Sepal.L = c(5, 6, 7), Sepal.W = c(2.5, 3.5))
mod2 <- nb2(iris[, 1:4], iris[, 5], discretize = "fixed",
            discParams = discParam)
preds <- predict(mod2, iris[, c(1, 3)])
iris2 <- cbind(iris, err = (preds != iris$Species))
plot(mod2, features = c(1, 3), xlim = c(4, 8), ylim = c(0, 8)) +
  geom_point(aes(x = Sepal.Length, y = Petal.Length, shape = Species),
             data = subset(iris2, iris2$err), size = 3.5, col = "white",
             show.legend = FALSE) +
  geom_point(aes(x = Sepal.Length, y = Petal.Length, shape = Species),
  data = iris2, size = 2) +
  guides(colour = FALSE, shape = FALSE)

aschersleben/NBCD documentation built on May 12, 2019, 4:32 a.m.