naiveBayes {e1071} | R Documentation |
Computes the conditional a-posterior probabilities of a categorical class variable given independent categorical predictor variables using the Bayes rule.
naiveBayes(formula, data, ..., subset, na.action = na.pass)
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 NA s 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.) |
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. |
David Meyer david.meyer@ci.tuwien.ac.at
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])