Conditional Probability
By: Jackson Bull
Tags: Decision Tree, Statistics, Visual Thinking, Probability, Data Science

If you’re currently in the job market or looking to switch careers, you’ve probably noticed an increase in popularity of Data Science jobs. In 2019, LinkedIn ranked “data scientist” the №1 most promising job in the U.S. based on job openings, salary, and career advancement opportunities and reported a 56% rise in job openings for data scientists over the previous year. Despite its popularity, however, data science can me a difficult field to enter, let alone to learn. I know from my personal experience, the amount of statistics involved made it very challenging. Probability, in particular, can be quite complicated but is fundamental to many machine learning models such as decision tree learning. So the purpose of this article is to provide a rudimentary undertanding of conditional probability.

How To Calculate Probability

Simply put, the probability of an event happening is equal to the number of times an event could happen divided by the total number of outcomes. For example, imagine you have a deck of cards and you want to calculate the probability that you’ll randomly pull a king from the deck. How would you calculate that? Well, since there are 4 kings in a deck of cards, there are 4 possible ways you can draw a king from the deck; and since there are 52 cards in the deck, there’s 52 possible outcomes. So 4 divided by 52 is .076 or 7.6% chance your card will be a king. Now say you want to figure out the probability of drawing another king — the answer will depend on how you handle replacement. Sampling with replacement means that you place the first card back into the deck making the two events independant (the probability of drawing each king doesn’t change). Sampling without replacement means you’re not placing the first card back, which affects the probability of drawing the second king (total number of outcomes is now 51). If event A is drawing the first king card and event B os drawing the second king card, then we’d say the probability of B given A is equal to the probability of event A multiplied by the probability of event B given that A occurs.

Mathematical Notation

P(A and B) = P(A) x P(B|A) = 4/52 x 3/51 = .45%

Tree Diagram

Mathematics isn’t intuitive to everyone; it certainly wasn’t for me as I was just starting out in this field. Visualizations, however, can be a great tool when it comes to reenforcing complex topics. A tree diagram is one example that can help you break down a general problem into smaller components — perfect for probability problems that involves multiple events that lead to a variety of outcomes. For example, take a look at the diagram I’ve created that helps answer the following question: If you have a bag of 23 marbles (5 green, 8 blue, and 10 red), what’s the probability that you’ll randomly pull out a blue marble and a green marble? Let’s break it down.

The probability of grabbing a blue marble is 35%, because there are 8 way you can get a blue marble and 23 total potential outcomes. Now given that you pulled out a blue marble, the probability of grabbing a green marble from the bag is 23% — 5 green marbles divided by 22 potential outcomes (notice how the total number of outcomes changes the second time, hence the change in probability). Finally, calculating the probability of both these events happening involves multiplying the probability of both events (.35 x .23 = 8%).

Conclusion

Hopefully this demsonstration has given you a clearer mental picture of statistical probability. Even though conditional probability may seem elementary compared to the more advanced concepts in machine learning, having a solid understanding of the foundation of which data science is built on is extremely important. So whenever you begin to learn something new, remember that no topic is too small and relearning is reenforcement.