# [R] Making model predictions

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sat Feb 27 20:36:58 CET 2021

```The standard approach for prediction is via a predict() method for the
class of the model fit. So, have you checked
?predict.naiveBayes

If this does not satisfy your needs, you are on your own. Possibly your
best course of action then is to contact the maintainer as the posting
guide (linked below) recommends for "non-standard" packages. (?maintainer)

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Sat, Feb 27, 2021 at 6:42 AM Jeff Reichman <reichmanj using sbcglobal.net>
wrote:

> R User Forum
>
> Is there a better way than grabbing individual cell values from a model
> output to make predictions. For example the output from the following Naïve
> Bayes model
>
> library(e1071)
>
> ## Example of using a contingency table:
> data(Titanic)
> m <- naiveBayes(Survived ~ ., data = Titanic)
> m
>
> will produce the following results:
>
> Call:
> naiveBayes.formula(formula = Survived ~ ., data = Titanic)
>
> A-priori probabilities:
> Survived
>       No      Yes
> 0.676965 0.323035
>
> Conditional probabilities:
>         Class
> Survived        1st        2nd        3rd       Crew
>      No  0.08187919 0.11208054 0.35436242 0.45167785
>      Yes 0.28551336 0.16596343 0.25035162 0.29817159
>
>         Sex
> Survived       Male     Female
>      No  0.91543624 0.08456376
>      Yes 0.51617440 0.48382560
>
>         Age
>      No  0.03489933 0.96510067
>      Yes 0.08016878 0.91983122
>
> Say I want to calculate the probability of P(survival = No | Class = 1st,
> Sex = Male, and Age= Child).
>
> While I  can set an object (e.g. myObj <- m\$tables\$Class[1,1])  to the
> respective cell and perform the calculation, there must be a better way, as
> I continue to learn R.
>
> Jeff
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help