Probability Fundamentals
Introduction
Probability is a fundamental concept in data science and machine learning, serving as the backbone for statistical inference and decision-making under uncertainty. This lesson covers the essential concepts, definitions, and rules of probability.
Key Concepts
- Random Experiment
- Sample Space
- Event
- Probability of an Event
- Conditional Probability
- Independence
Definitions
Random Experiment
An action or process that leads to one or more outcomes.
Sample Space (S)
The set of all possible outcomes of a random experiment.
Event (E)
A subset of the sample space. An event can consist of one or more outcomes.
Probability of an Event (P(E))
The likelihood of an event occurring, defined as the ratio of the number of favorable outcomes to the total number of outcomes in the sample space.
Conditional Probability
The probability of an event occurring given that another event has already occurred.
Independence
Two events are independent if the occurrence of one does not affect the occurrence of another.
Basic Rules of Probability
- Rule of Addition: For any two events A and B,
P(A ∪ B) = P(A) + P(B) - P(A ∩ B) - Rule of Multiplication: For any two independent events A and B,
P(A ∩ B) = P(A) * P(B) - Complement Rule: The probability of an event not occurring,
P(A') = 1 - P(A)
Code Examples
Below is a simple Python example demonstrating basic probability calculations:
import random
# Function to simulate a random experiment
def simulate_experiment(trials):
success_count = 0
for _ in range(trials):
outcome = random.choice(['H', 'T']) # Heads or Tails
if outcome == 'H':
success_count += 1
return success_count / trials
# Run the experiment
probability_of_heads = simulate_experiment(10000)
print(f"Estimated Probability of Heads: {probability_of_heads:.4f}")
FAQ
What is the difference between independent and mutually exclusive events?
Independent events do not influence each other's occurrence, while mutually exclusive events cannot occur at the same time.
How do you calculate conditional probability?
Conditional probability can be calculated using the formula: P(A|B) = P(A ∩ B) / P(B).
What is Bayes' theorem?
Bayes' theorem describes the probability of an event based on prior knowledge of conditions related to the event. It is expressed as:
P(A|B) = (P(B|A) * P(A)) / P(B).