MATLAB: Naive Bayes Posterior Probability

bayesfitcnbnaive bayesposteriorprobability

Hi,
I am using a Naive Bayes Classifier which I train with:
Mdl = fitcnb(data,target,...
'Holdout',0.10,...
'OptimizeHyperparameters','auto',...
'HyperparameterOptimizationOptions',...
struct('AcquisitionFunctionName','expected-improvement-plus'));
So when I predit the class of the data results in values of 0 and 1, because I only have two classes. This is pretty nice, but I need to know the certainty of this estimate. So I want to have something like:
class 1: probability 0.4
class 2: probability 0.6
or something like this.
Is the correct function for this the posterior function? As far as I understood it this function is only available for the deprecated NaiveBayes class.
Does anybody know how I can get the probability of the estimate?

Best Answer

You can get the posterior probabilities from the second output of the predict method. See this page: http://www.mathworks.com/help/stats/compactclassificationnaivebayes.predict.html
[label,Posterior] = predict(Mdl,X)