๐ Phase 2: Mathematics for Data Science
๐ Topic 4: Probability Basics
Welcome back! ๐
In the previous lesson, you learned about Variance and Standard Deviation, which help us understand how data is spread out.
Now let's learn another fundamental concept in Data Science: Probability.
Probability helps us measure the likelihood that an event will happen. It plays an important role in Machine Learning, Statistics, Bayesian inference, risk analysis, forecasting, and decision-making.
๐น 1. What is Probability?
Probability is a measure of how likely an event is to occur.
Its value ranges from: 0 โค Probability โค 1
Where:
0 โ Impossible event
1 โ Certain event
0.5 โ 50% chance
Probability can also be expressed as a percentage.
0.25 = 25%
0.50 = 50%
0.75 = 75%
1.00 = 100%
๐น 2. Basic Probability Formula
When all possible outcomes are equally likely:
Probability(Event) =
Number of favorable outcomes
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Total number of possible outcomes
Example
Roll a standard six-sided die: 1, 2, 3, 4, 5, 6
What is the probability of getting a "4"?
1 favorable outcome, 6 possible outcomes
P(4) = 1/6 โ 0.167 = 16.7%
๐น 3. Experiment, Outcome & Event
Experiment: An action that produces an outcome. Ex: Rolling a die
Outcome: A possible result. Ex: 1, 2, 3, 4, 5, or 6
Event: A specific outcome or group of outcomes we're interested in. Ex: Getting an even number โ 2, 4, 6
๐น 4. Sample Space
The set of all possible outcomes.
Coin toss: S = {Head, Tail}
Die: S = {1, 2, 3, 4, 5, 6}
๐น 5. Probability of an Event
Roll a die and want an even number.
Favorable: 2, 4, 6
P(Even) = 3/6 = 0.5 = 50%
๐น 6. Complementary Probability โญ
The complement of an event means the event does not happen.
If P(A) = 0.7
Then: P(Not A) = 1 - P(A) = 1 - 0.7 = 0.3
So there is a 30% probability that A will not occur.
๐น 7. Independent Events
Two events are independent when the occurrence of one does not affect the other.
Ex: Tossing a coin twice.
For independent events: P(A and B) = P(A) ร P(B)
Ex: P(Head and Head) = 1/2 ร 1/2 = 1/4 = 25%
๐น 8. Dependent Events
Two events are dependent when the outcome of one affects the probability of the other.
Ex: Bag with 3 Red, 2 Blue balls. Pick one and don't put it back. The probability for the second pick changes.
๐น 9. Conditional Probability โญ
Probability of an event occurring given that another event has already occurred.
Written as: P(A | B) โ "Probability of A given B"
Formula: P(A | B) = P(A โฉ B) / P(B)
๐น 10. Real-World Example of Conditional Probability
Company data:
60% customers using Mobile App
30% customers using Mobile App and making a purchase
P(Purchase | App) = P(Purchase โฉ App) / P(App) = 0.30 / 0.60 = 0.50
Therefore: 50% of app users make a purchase.
๐น 11. Addition Rule
For two events: P(A or B) = P(A) + P(B) - P(A and B)
If mutually exclusive: P(A or B) = P(A) + P(B)
๐น 12. Multiplication Rule
For independent events: P(A and B) = P(A) ร P(B)
Ex: Rolling two sixes: P(6 and 6) = 1/6 ร 1/6 = 1/36
๐น 13. Probability in Data Science โญ
Machine Learning: Models produce probabilities. Ex: P(Spam) = 0.92
Classification: P(Customer will churn) = 78%
Risk Analysis: Estimate likelihood of loan default, fraud, churn, equipment failure
๐น 14. Probability vs Statistics
Probability: Starts with assumptions and predicts possible outcomes. Known model โ Predict outcomes
Statistics: Starts with observed data and tries to understand the underlying population. Observed data โ Learn about the model
๐น 15. Python Example
favorable = 3
total = 6
probability = favorable / total
print(probability)