Published in

Analytics Vidhya

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

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.

## Likelihood

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.

## Example:

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.

--

--

## More from Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

## Harshit Dawar

Big Data Enthusiast, have a demonstrated history of delivering large and complex projects. Interested in working in the field of AI and Data Science.