plot.gaussian_naive_bayes: Plot Method for gaussian_naive_bayes Objects

View source: R/gaussian_naive_bayes.R

plot.gaussian_naive_bayesR Documentation

Plot Method for gaussian_naive_bayes Objects


Plot method for objects of class "gaussian_naive_bayes" designed for a quick look at the class marginal or conditional Gaussian distributions of metric predictors.


## S3 method for class 'gaussian_naive_bayes'
plot(x, which = NULL, ask = FALSE, legend = TRUE, = FALSE, arg.num = list(),
  prob = c("marginal", "conditional"), ...)



object of class inheriting from "gaussian_naive_bayes".


variables to be plotted (all by default). This can be any valid indexing vector or vector containing names of variables.


logical; if TRUE, the user is asked before each plot, see par(ask=.).


logical; if TRUE a legend will be be plotted.

logical; if TRUE a box will be drawn around the legend.


other parameters to be passed as a named list to matplot.


character; if "marginal" then marginal distributions of predictor variables for each class are visualised and if "conditional" then the class conditional distributions of predictor variables are depicted. By default, prob="marginal".


not used.


Class marginal and class conditional Gaussian distributions are visualised by matplot.

The parameter prob controls the kind of probabilities to be visualized for each individual predictor Xi. It can take on two values:

  • "marginal": P(Xi|class) * P(class)

  • "conditional": P(Xi|class)


Michal Majka,

See Also

naive_bayes, gaussian_naive_bayes, predict.gaussian_naive_bayes, tables, get_cond_dist


y <- iris[[5]]
M <- as.matrix(iris[-5])

### Train the Gaussian Naive Bayes with custom prior
gnb <- gaussian_naive_bayes(x = M, y = y, prior = c(0.1,0.3,0.6))

# Visualize class marginal Gaussian distributions corresponding
# to the first feature
plot(gnb, which = 1)

# Visualize class conditional Gaussian distributions corresponding
# to the first feature
plot(gnb, which = 1, prob = "conditional")

naivebayes documentation built on June 25, 2024, 1:16 a.m.