Welcome to our lesson on "Probability Basics"! This topic is important for making predictions and understanding uncertainties in machine learning. By the end of this lesson, you'll know the essentials of probability and how to calculate probabilities for different events using Python.
Let's begin by understanding what probability is and why it matters.
Probability measures the likelihood of an event happening. Think of it as quantifying uncertainty. For example, what are the chances it will rain tomorrow, or that a flipped coin will land on heads?
Mathematically, the probability of an event happening can be represented as:
Probability ranges from 0 (an impossible event) to 1 (a certain event).
Let's use a deck of playing cards to understand probabilities practically. A standard deck has 52 cards. We'll calculate the probability of different events using these cards.
Imagine we want to calculate the probability of drawing an Ace from a standard deck.
Example:
In Python:
In the print
function, .2f
is a format specifier that limits the displayed output to 2 decimal places.
Next, let's calculate the probability of drawing a card from the Hearts suit.
Example:
In Python:
This rule states that the probability of one of two mutually exclusive events happening is the sum of their individual probabilities.
Mutually exclusive events are events that cannot happen at the same time. In the context of drawing cards, drawing an Ace and a King are mutually exclusive because you can't draw both at the same time from a single draw.
For example, the probability of drawing either an Ace or a King:
In Python:
When two events are not mutually exclusive, they can happen at the same time. In this case, we need to subtract the probability of both events happening from the sum of their individual probabilities to avoid double-counting.
For example, consider the probability of drawing a card that is either an Ace or a Heart. Since the Ace of Hearts fits both categories, it needs to be subtracted once.
In Python:
The next rule applies to independent events, like drawing cards with replacement. Drawing with replacement means that after drawing a card, you place it back in the deck before drawing again. This ensures that the total number of cards remains the same for each draw.
The probability of both events happening is the product of their individual probabilities. For example, here is how we can calculate the probability of drawing a King and and Ace from two draws, given that we put the first card back and shuffle before the second draw.
Example:
In Python:
When events are dependent, like drawing cards without replacement, the probability changes after the first event.
Example: If you draw an Ace first, there are now 51 cards left in the deck, and only 4 of them are Kings. So, the probability of drawing a King is no longer , it is now
Here, represents the conditional probability, i.e., the probability of drawing a King given that an Ace has already been drawn.
Therefore,
In Python:
Great job! Today we covered the basics of probability, including how to calculate probabilities for different events. We explored different types of events: mutually exclusive, non-mutually exclusive, independent, and dependent events to understand their probabilities.
By now, you should be comfortable with the basic probability concepts and calculations.
Next, you will move to a practice session where you will apply these concepts and solidify your understanding. Let's move on to practice!
