# Any way of getting vector of probabilities for each response with Naive Bayes in R?

I'm currently using naiveBayes from {e1071}. My response is simply a prediction based on my independent variables. Is there a way to get the probability for each possible prediction as a response with naiveBayes? So if I was trying to predict the outcome of a race, the predicted results would look like this :

Name    position  prob
Tom          1    0.1
Tom          2    0.2
Tom          3    0.7
Jim          1    0.2
Jim          2    0.5
Jim          3    0.3
Elizabeth    1    0.8
Elizabeth    2    0.1
Elizabeth    3    0.1


As opposed to just

Name        position
Tom            3
Jim            2
Elizabeth      1


If this is not possible with Naive Bayes, are there any other standard models that would support this? Like a Random Forest for instance? I would appreciate any guidance/literature on the matter.

You just need to set type = "raw" in the predict object.
require(e1071)

• Thank you @Firebug. Just a few follow up questions. What other values can be given to the type argument? I couldn't find much here: stat.ethz.ch/R-manual/R-devel/library/stats/html/…. Also will the prediction always be given with the responses as features and probabilities as observations? (in which case I would just have to pivot it right?). Thanks again – jgozal May 31 '16 at 0:06
• @jgozal the way R documentation is structured you should actually look at the packages in question, so look for naiveBayes in the e1071 manual. The only types really are classes and raw. And yeah, all R predict functions I know will output predicted probabilities in that format. – Firebug May 31 '16 at 1:21
• ah interesting. I wasn't aware e1071 and R packages in general could introduce arguments into stats functions. Thank you! – jgozal May 31 '16 at 2:55