2
$\begingroup$

I have designed NB classifier from scratch in python for binary classification problem. There are total 220 records out of which 85 records belongs to 'Yes' class and 135 to 'No' class. My classifier is giving 88% accuracy.

So, whenever I calculate the posterior probability of one sample that belongs to 'Yes' class it is very low in terms of numbers. For eg., I'm making a prediction that whether the batsman is rising star (i.e. the probability of sample belongs to 'Yes' class ).

Here The posterior probability of being rising star i.e. P(RS) is very low in numbers something like 2.33E-8. But the posterior probability of being not rising star is also very low similar in the range of E-8 to E-16. Some features I'm using to calculate posterior probability are also small values in the range of 0.1 to 0.01.

My question is how to represent posterior probability i.e. P(RS) in terms of percentage. Like P(RS)=90%.

PS: I googled this problem and tried log method which returns a negative value.

$\endgroup$
3
$\begingroup$

I can't tell you for sure without you describing your calculation more or showing code, but my guess is you're not actually calculating the posterior probability here. I bet this is just the conditional likelihood, or at best the unnormalized posterior. Remember: the posterior calculation has a division component. Does yours? You're probably forgetting to divide by the "evidence".

$\endgroup$
  • $\begingroup$ Yup. you are right. I'm not doing division. I took reference from this article. In this article, they have written that It is ok if you don't divide by marginal probability. So are you saying that low number is because of skipping division part? $\endgroup$ – Scorpionk Jan 21 '18 at 4:43
  • $\begingroup$ If you're just using NB to generate classifications, you can ignore the divisor because it's going to be the same for every calculation. The classification decision is "which class gives the highest score?" and the answer to that question doesn't change if you ignore the divisor. In other words, the output is proportional to the posterior, but is not actually the posterior. If you want the posterior, you need that denominator. $\endgroup$ – David Marx Jan 21 '18 at 12:31
  • $\begingroup$ Yup. Got it. Now if I want to calculate posterior, how should I calculate denominator? I have to calculate P(data) but it is not categorical, it is numerical. $\endgroup$ – Scorpionk Jan 22 '18 at 6:36
1
$\begingroup$

The question is a bit fuzzy so if i did not get the point please comment me. You have a binary classification problem and you want to solve it using NB. Well, then you go through Bayes formula:

$P(class|data)=P(data|class)P(class)$

This is the representation of each class GIVEN a sample point i.e. this representation varies according to feature values. The simple percentage of each class does not need NB.

If the probability of predictions for one class on validation set is low it means that they were not from that class! For more detailed answer please say how did you set up your train/test split and what were these small numbers?

If some numbers are strange then you may need to attach your code as well.

Update

My question is how to represent posterior probability i.e. P(RS) in terms of percentage. Like P(RS)=90%.

When you get probabilities out then 100 times of it is percentage. So let's focus on probabilities.

The above formulation is simplified for classification. The complete formulation is

$P(class|data)=\frac{P(data|class)P(class)}{P(data)}$

As the denumerator is a probability, so it is between 0 and 1, it increases the whole fraction but it's not used in classification task as it's practically constant! Therefore as you want to see the probability (percentage) of your posterior, maybe including it in your formula solves the your problem.

Hope it helps!

$\endgroup$
  • $\begingroup$ Edited. I hope now you will understand it. $\endgroup$ – Scorpionk Jan 20 '18 at 18:22
  • $\begingroup$ That equation you posted is wrong and is probably exactly the same mistake OP is making. $\endgroup$ – David Marx Jan 20 '18 at 20:19
  • $\begingroup$ I think i got your point $\endgroup$ – Kasra Manshaei Jan 20 '18 at 20:32
  • $\begingroup$ Yup. You got it. I'm not doing any division. I used this reference. They have written the same thing. They skipped division part (marginal probability). $\endgroup$ – Scorpionk Jan 21 '18 at 4:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.