Conditional Probability Explained with Real Life Applications

What Is Conditional Probability?

Conditional probability, in probability theory, is defined as the measure of the likelihood of an event occurring, assuming that another event or outcome has previously occurred. It is expressed as the multiplication of the probability of the previously occurred event with the probability of the conditional event that has occurred in succession. 

So, if we have events A and B where P(B)>0, we calculate the conditional probability of A when B has already occurred, P(A | B) as

P(A | B)=P(A∩B)P(B)

  • | is used to denote “given” in “cases where another event occurs”
  • ∩ is used to denote intersection

While computing the conditional probability, it is assumed that we are aware of the outcome of event B. This is especially useful since the information of an experiment’s outcome is often unknown. 

Let’s understand this with an example: 

  • We have an event A where we assume that an individual who has applied to a university will be accepted. The probability of them getting accepted is 70%. 
  • We have another event B where there is a 50% chance that accepted students will be assigned dormitory housing. 

Hence, we calculate the conditional probability as, 

Probability (Students Accepted and Dormitory Assigned) = P (Dormitory Assigned | Students Accepted) × P (Students Accepted)

= (0.50)*(0.70) = 0.35

With conditional probability, we are looking at both events A and B, their relationship with each other where a student is both accepted to the university and is assigned dormitory housing.

In contrast, unconditional probability is defined as the measure of the probability that an event will occur regardless of whether it is preceded by another event or has other conditions given.

Real-Life Applications of Conditional Probability

Conditional probability finds extensive use in different fields such as insurance and calculus. It is also applicable in politics. Let’s assume there is an expected re-election of a president. The results will depend on the preferences of those eligible to vote and the probability of the outcome of television advertising campaigns. 

In another example, let’s assume that the probability of rain in your area is 40% as specified by the weather. However, this outcome is largely dependent on:

  • Whether there are clouds forming in your area
  • Whether there is the possibility of a cold front arriving in your area
  • Whether the clouds are being pushed away by another front

The conditional probability will depend on each of the above events. 

Bayes’ Theorem

Introduced by mathematician Thomas Bayes, Bayes’ theorem or Bayes’ Rule or Bayes’ Law is a mathematical equation that helps calculate conditional probability. Using Bayes’ theorem, we can revise (update) existing measures of probability when new evidence or additional information comes to light.

Bayes’ theorem finds use in finance where accountants use it to determine the risk of loaning money to a borrower. In addition to this, it is also useful in statistics and inductive logic.

Bayesian statistics is based on Bayes’ theorem where it is possible to predict events on the basis of new evidence, thereby leading to more dynamic and accurate estimates. 

Join the Machine Learning Course online from the World’s top Universities – Masters, Executive Post Graduate Programs, and Advanced Certificate Program in ML & AI to fast-track your career.

Conditional Probability Example with Python

In this example, we will use conditional probability to determine the probability of a student getting an A grade (80%+) in Physics, provided that they skip a minimum of 10 classes.

To begin with, inspect the dataset you download from kaggle:

import pandas as pd

df = pd.read_csv(‘student-alcohol-consumption/student-mat.csv’)

df.head(3)

Go through the number of records:

len(df)

#=> 395

We will only take the following columns into account: the number of absences and final grades.

Now, create a new boolean column grade_A to show if a student’s final score is 80% or higher. 

Multiply by 5:

df[‘grade_A’] = np.where(df[‘G3’]*5 >= 80, 1, 0)

Create a new boolean column high_absenses having value 1 denoting students who missed a minimum of 10 classes.

df[‘high_absenses’] = np.where(df[‘absences’] >= 10, 1, 0)

Create another column so we can easily build a pivot table:

df[‘count’] = 1

Remove all the other columns:

df = df[[‘grade_A’,’high_absenses’,’count’]]

df.head()

Building a pivot table:

pd.pivot_table(

    df, 

    values=’count’, 

    index=[‘grade_A’], 

    columns=[‘high_absenses’], 

    aggfunc=np.size, 

    fill_value=0

     )

Now, we can proceed to our calculation: 

  • P(A) denotes the probability of a student scoring an A grade (80% or greater).
  • P(B) is the probability that a student has missed a minimum of 10 classes.
  • P(A|B) is the probability that a student has scored an 80%+ grade, given that he/she missed a minimum of 10 classes. 

P(A) = (35 + 5) / (35 + 5 + 277 + 78) = 0.10126…

P(B) = (78 + 5) / (35 + 5 + 277 + 78) = 0.21012…

P(A ∩ B) = 5 / (35 + 5 + 277 + 78) = 0.0126582…

P(A|B) = P(A ∩ B) / P(B) = 0.06

As per our calculations, the probability that a student has scored an 80%+ grade, given that he/she missed a minimum of 10 classes is at least 6%.

Conditional Probability of Independent Events

We also have events, say A and B where both are independent events, which means the occurrence of event A has no relation with the occurrence of event B.

In such a case, the conditional probability P(B|A) is essentially P(B). 

P(B|A)= P(B)

Similarly, the conditional probability P(A|B) is essentially P(A).

 P(A|B)= P(A)

Conditional Probability of Mutually Exclusive Events

As per probability theory, when we talk about events that can not occur at the same time, we are talking about mutually exclusive. To put it simply, if event A has occurred, event B cannot occur simultaneously. Therefore, in such cases, the probability is always zero.

P(B|A)= 0 and P(A|B)= 0

Law of Total Probability

We use the multiplication rule to determine the probability of complex cases. 

As per the multiplication rule, we calculate the probability of events, E and F, both of which are observing events, by multiply the probability of the observing event F and observing event E, given that event F has already been observed.

P( E1 ⋂ E2 ⋂….. ⋂En)=P( E1) P(E2 | E1)………P(En | E1…………En-1)

Now, let’s assume we have a sample space S comprising three disjoint events X, Y, Z. Therefore

P(A)=P(A ⋂ X) +P(A ⋂ Y) +P(A ⋂ Z)

Now, as per the multiplication rule, the law of total probability can be expressed as 

 P(A)= P(A|X) P(X) +P(A|Y) P(Y) +P(A| Z) P(Z)

Conclusion

Understanding conditional probability is necessary to master complex probability estimations that are carried out using Bayes’ theorem. If you’d like to learn in-depth about conditional probability and the Bayes’ theorem, we recommend joining our IIT-Advanced Certificate Program in Machine Learning

upGrad’s platform of 40,000+ provides opportunities for peer-to-peer collaboration and 360° job assistance at top firms. With rigorous training through hands-on projects, case studies, live lectures, students can master the complicated concepts of probability and leverage them to deploy Machine Learning models. 

Lead the AI-driven technological revolution. Apply Now! 

What is Joint Probability?

It is the measure of the probability of two events occurring simultaneously at the same point in time. In simple words, joint probability the likelihood of event B occurring at the same point in time as event A.

Is conditional probability commutative or not?

It is not commutative.

What is the need for conditional probability?

Conditional probability makes it easier to estimate the probability of an event based on the conditioned evidence which depends on first principles.

Enhance Your Career in Machine Learning and Artificial Intelligence

0 replies on “Conditional Probability Explained with Real Life Applications”

×