Clear Filters
Clear Filters

need to calculates the Posterior probability using fitcnb function classification

4 views (last 30 days)
I need quick help with modifications of the attached code which calculates the prior probability and I need to add a function that calculates the Posterior probability of the data using fitcnb classification function
I tried with to apply similar code of this example but I couldn't fit it into my code
these are the classes inside my dataset
'BENIGN','DrDoS_DNS','DrDoS_LDAP','DrDoS_MSSQL','DrDoS_NetBIOS','DrDoS_NTP','DrDoS_SNMP','DrDoS_SSDP','DrDoS_UDP','Syn','UDP-lag'
where the distribution of BENIGN label should be 50% and the other 50% should be all other labels
Thanks in advance realy appreciate your help

Answers (1)

Avadhoot
Avadhoot on 26 Sep 2023
Hi Ibtihal,
I understand that you have already created a Naïve Bayes Classifier using the “fitcnb” function. To calculate the posterior probabilities, you need to add the following line to your code after the creation of the model.
[labels,PostProbs,MisClassCost] = predict(Mdl,xdata);
The variables in the above line of code contain the following information:
  • “Mdl”: Naïve Bayes classifier model.
  • “xdata”: Input data for which you want to calculate the posterior probabilities.
  • “PostProbs”: Posterior probabilities of all the classes in your case.
  • “labels”: The predicted labels for your input data.
  • “MisClassCost”:Misclassification costs for all the classes in each data point.
For more information on how the posterior probabilities and misclassification costs are estimated, refer to the following link:
Regards,
Avadhoot.

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!