Plot method for objects of class "poisson_naive_bayes"
designed for a quick look at the class marginal or class conditional Poisson distributions of non-negative integer predictors.
# S3 method for poisson_naive_bayes
plot(x, which = NULL, ask = FALSE, legend = TRUE,
legend.box = FALSE, arg.num = list(),
prob = c("marginal", "conditional"), ...)
object of class inheriting from "poisson_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.
Michal Majka, michalmajka@hotmail.com
Class marginal or class conditional Poisson distributions are visualised by matplot
.
The parameter prob
controls the kind of probabilities to be visualized for each individual predictor
"marginal":
"conditional":
naive_bayes
, poisson_naive_bayes
, predict.poisson_naive_bayes
, tables
, get_cond_dist
cols <- 10 ; rows <- 100
M <- matrix(rpois(rows * cols, lambda = 3), nrow = rows, ncol = cols)
# is.integer(M) # [1] TRUE
y <- factor(sample(paste0("class", LETTERS[1:2]), rows, TRUE))
colnames(M) <- paste0("V", seq_len(ncol(M)))
laplace <- 0
### Train the Poisson Naive Bayes
pnb <- poisson_naive_bayes(x = M, y = y, laplace = laplace)
# Visualize class conditional Poisson distributions corresponding
# to the first feature
plot(pnb, which = 1, prob = "conditional")
# Visualize class marginal Poisson distributions corresponding
# to the first feature
plot(pnb, which = 1)
Run the code above in your browser using DataLab