infix_class_prob function

Predict Method for Family of Naive Bayes Objects

Predict Method for Family of Naive Bayes Objects

The infix operators %class% and %prob% are shorthands for performing classification and obtaining posterior probabilities, respectively.

lhs %class% rhs lhs %prob% rhs

Arguments

  • lhs: object of class inheriting from "naive_bayes" and "*_naive_bayes" family.
  • rhs: dataframe or matrix for "naive_bayes" objects OR matrix for all "*_naive_bayes" objects.

Returns

  • %class% returns factor with class labels corresponding to the maximal conditional posterior probabilities.
  • %prob% returns a matrix with class label specific conditional posterior probabilities.

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.

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")

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