Infix operators {naivebayes} | R Documentation |
Predict Method for Family of Naive Bayes Objects
Description
The infix operators %class%
and %prob%
are shorthands for performing classification and obtaining posterior probabilities, respectively.
Usage
lhs %class% rhs
lhs %prob% rhs
Arguments
lhs |
object of class inheriting from |
rhs |
dataframe or matrix for "naive_bayes" objects OR matrix for all "*_naive_bayes" objects. |
Details
If lhs
is of class inheriting from the family of the Naive Bayes objects and rhs
is either dataframe or matrix then the infix operators %class%
and %prob%
are equivalent to:
-
lhs %class% rhs
<=>predict(lhs, newdata = rhs, type = "class", threshold = 0.001, eps = 0)
-
lhs %prob% rhs
<=>predict(lhs, newdata = rhs, type == "prob", threshold = 0.001, eps = 0)
Compared to predict()
, both operators do not allow changing values of fine tuning parameters threshold
and eps
.
Value
-
%class%
returns factor with class labels corresponding to the maximal conditional posterior probabilities. -
%prob%
returns a matrix with class label specific conditional posterior probabilities.
Author(s)
Michal Majka, michalmajka@hotmail.com
See Also
predict.naive_bayes
, predict.bernoulli_naive_bayes
, predict.multinomial_naive_bayes
, predict.poisson_naive_bayes
, predict.gaussian_naive_bayes
, predict.nonparametric_naive_bayes
Examples
### Fit the model
nb <- naive_bayes(Species ~ ., iris)
newdata <- iris[1:5,-5] # Let's pretend
### Classification
nb %class% newdata
predict(nb, newdata, type = "class")
### Posterior probabilities
nb %prob% newdata
predict(nb, newdata, type = "prob")