naiveBayes {e1071}R Documentation

Naive Bayes Classifier

Description

Computes the conditional a-posterior probabilities of a categorical class variable given independent categorical predictor variables using the Bayes rule.

Usage

naiveBayes(formula, data, ..., subset, na.action = na.pass)

Arguments

formula A formula of the form class ~ x1 + x2 + .... Interactions are not allowed.
data Either a data frame of factors or a contingency table.
... Currently not used.
subset For data given in a data frame, an index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named.)
na.action A function to specify the action to be taken if NAs are found. The default action is not to count them for the computation of the probability factors. An alternative is na.omit, which leads to rejection of cases with missing values on any required variable. (NOTE: If given, this argument must be named.)

Value

An object of class "naiveBayes" including components:

apriori Class distribution for the dependent variable.
tables A list of probability tables, one for each predictor variable, giving, for each attribute level, the conditional probabilities given the predictor classes.

Author(s)

David Meyer david.meyer@ci.tuwien.ac.at

See Also

predict.naiveBayes

Examples

data(HouseVotes84)
model <- naiveBayes(Class ~ ., data = HouseVotes84)
predict(model, HouseVotes84[1:10,-1])
predict(model, HouseVotes84[1:10,-1], type = "raw")

pred <- predict(model, HouseVotes84[,-1])
table(pred, HouseVotes84$Class)

data(Titanic)
m <- naiveBayes(Survived ~ ., data = Titanic)
m
predict(m, as.data.frame(Titanic)[,1:3])


[Package Contents]