Analytics Vidhya
Published in

Analytics Vidhya

All about Bayes Theorem!

Source: Gerd Altmann from Pixabay

Ever wondered about calculating the probability of an event based on some other event, it would have been fun right! If till now you have not figured out trying the above scenario, I will help you and explain how it is possible and also it is too much fun.

In mathematics world, if we are trying to find out the probability of an event based on occurrence of another event, we denote it with “|” symbol between the two events. For Example, P(Happy | Watched a movie), where “P” represent Probability and the inner two are events, and the above equation signifies the probability of a person being happy given that he/she has watched a movie[I have taken this example in context with a person].

Bayes Theorem Equation

Image by Author

In the given image above, “A” & “B” are events, and in order to find the probability of occurrence of event “A” given that event “B” has already occurred, is calculated by the above equation, where “P” always represents “probability.”

Bayes Theorem is based on the 4 concepts, those are “Likelihood”, “Prior Probability”, “Marginal Probability”, & “Posterior Probability”!

Prior Probability

It signifies the probability of the occurrence of an event(our hypothesis) before the occurrence of another event or we can say before observing the evidence.

Marginal Probability

It signifies the probability of the occurrence of an event(actual event/evidence or the event which we are considering to already occur) to occur in all the possibilities of our hypothesis.


It signifies the probability of an event to be true/ or to occur if we consider our hypothesis to be true, or we can say that another event(out hypothesis) has already occurred.

Posterior Probability

It signifies the probability of occurrence of an event (our hypothesis) given that another event has already occurred.

If we are given with the first 3 parameters from the above list of 4 parameters, we can easily predict the final one using the Bayes Theorem.


Consider that we have to find the probability for a person to be happy after it has watched a movie.

Consider the below-given probabilities initially:

  1. P(Happy) = 0.9
  2. P(Watch a movie) = 0.95
  3. P(Watch a movie | Happy) = 0.5 < = it means that a person will watch a movie if it is happy.

Now, we have to calculate P(Happy | Watch a movie)

Using Bayes Theorem in the above situation, we can definitely calculate our desired outcome.

P(Happy | Watch a Movie) = [ P(Watch a Movie | Happy) * P(Happy) ] / P(Watch a Movie)

P(Happy | Watch a Movie) = (0.5 * 0.9) / (0.95) = 0.4736

Above is the probability calculated for a person who is happy after watching a movie according to the above data.

I hope this article explains the Bayes Theorem in a well-explained manner. Thank you so much for giving me your time.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store