Guozhen AIGlobal AI field notes and model intelligence

English translation

Set seed for reproducibility

Published:

Category: Probability Theory

Read time: 3 min

Reads: 0

Lesson #3Views are counted together with the original Chinese articleImages are preserved from the source page

Concept Map: Conditional Probability and Independence

Conditional probability is not merely ordinary probability with an extra symbol—it redefines the scope of discussion given that a particular event has occurred.

Conditional Probability and Independence Checklist

First ask: Does condition B alter the sample space? If it does, the denominator can no longer be the original total count.

Building upon our understanding of events and sample spaces, we now delve into two pivotal concepts in probability theory: conditional probability and independence. These ideas play indispensable roles in machine learning and data science—mastering them is therefore essential for deeper study and practical application.

Conditional Probability

Definition

Conditional Probability & Independence Decision Card

When learning conditional probability and independence, always begin by asking whether the new condition changes how we assess events. If the condition alters the probability, the events cannot simply be treated as mutually unaffected.

Conditional probability refers to the probability of one event occurring given that another event has already occurred. Mathematically, for events AA and BB, the conditional probability P(AB)P(A|B) denotes the probability that event AA occurs under the condition that event BB has occurred.

Formula

The formula for computing conditional probability is:

P(AB)=P(AB)P(B)P(A|B) = \frac{P(A \cap B)}{P(B)}

where P(AB)P(A \cap B) is the joint probability that both events AA and BB occur, and P(B)P(B) is the probability that event BB occurs.

Example

Consider a simple example: drawing a single card from a standard 52-card deck. Suppose we want to compute the conditional probability of drawing a red card (event AA), given that the drawn card is a heart (event BB).

  1. Event AA: Drawing a red card.
  2. Event BB: Drawing a heart.

In a standard deck, red cards consist of hearts (13 cards) and diamonds (13 cards). Since all hearts are red, P(AB)=P(drawing a heart)=1352P(A \cap B) = P(\text{drawing a heart}) = \frac{13}{52}, and P(B)=1352P(B) = \frac{13}{52}. Therefore:

P(AB)=P(AB)P(B)=13/5213/52=1P(A|B) = \frac{P(A \cap B)}{P(B)} = \frac{13/52}{13/52} = 1

This result indicates that, given the card drawn is a heart, the probability it is red is 1 (i.e., certain).

Code Example

We can simulate this scenario using Python:

import numpy as np

# Set seed for reproducibility
np.random.seed(42)

# Define suits
cards = ['♠', '♣', '♦', '♥']
total_cards = 52
red_cards = ['♦', '♥']

# Draw one card
drawn_card = np.random.choice(cards, p=[1/4]*4)
is_red = 1 if drawn_card in red_cards else 0

print(f"Drawn card: {drawn_card}, Is red: {bool(is_red)}")

Independence

Definition

Probability Application Decomposition Card

The article “Foundational Concepts in Probability: Conditional Probability and Independence” can be read through four lenses: scenario, concept, action, and outcome. First align these four elements; then revisit the parameters, code, or workflows described in the main text.

Two events are independent if the occurrence of one provides no information about the occurrence of the other. Formally, events AA and BB are independent if and only if:

P(AB)=P(A)P(B)P(A \cap B) = P(A) \cdot P(B)

Example

Suppose we have two completely independent experiments:

  1. Flipping a fair coin: event AA = “getting heads”.
  2. Rolling a fair six-sided die: event BB = “rolling a 4”.

We know:

  • Probability of heads: P(A)=12P(A) = \frac{1}{2}.
  • Probability of rolling a 4: P(B)=16P(B) = \frac{1}{6}.

Then the joint probability P(AB)P(A \cap B)—i.e., getting heads and rolling a 4—is:

P(AB)=P(A)P(B)=1216=112P(A \cap B) = P(A) \cdot P(B) = \frac{1}{2} \cdot \frac{1}{6} = \frac{1}{12}

Code Example

Here’s a simple Python simulation illustrating independence:

import numpy as np

# Sampling functions for coin flip and die roll
def flip_coin():
    return np.random.choice(['Heads', 'Tails'], p=[0.5, 0.5])

def roll_die():
    return np.random.randint(1, 7)  # integers 1 through 6

# Run many trials
trials = 10000
independent_events = [(flip_coin(), roll_die()) for _ in range(trials)]

# Count occurrences of (Heads, 4)
count = sum(1 for outcome in independent_events if outcome[0] == 'Heads' and outcome[1] == 4)
probability = count / trials

print(f"After {trials} trials, the empirical probability of 'Heads' and '4' occurring together is approximately: {probability:.4f}")

Application Recap Card: Foundational Concepts in Probability — Conditional Probability and Independence

If you haven’t fully internalized “Foundational Concepts in Probability: Conditional Probability and Independence”, revisit this card and walk through its four key actions step-by-step.

Application Check Card: Foundational Concepts in Probability — Conditional Probability and Independence

When reviewing “Foundational Concepts in Probability: Conditional Probability and Independence”, avoid jumping straight into large-scale projects. Instead, first verify conceptual clarity using a single, straightforward example.

Summary

After practicing the definitions, formulas, and computations related to conditional probability and independence, you should now possess a deeper, more intuitive grasp of these core probabilistic concepts. They are not only theoretically fundamental but also frequently encountered in real-world applications across data science and artificial intelligence. Next, we will explore random variables and their distributions in greater depth.

Continue

Keep reading from here

Browse English site

Reader Messages

Reader messages

Questions, corrections, extra sources, or hands-on results can be left here. No login is required.

Max 800 characters

To reduce spam, each message is checked for length, link count, and posting frequency.

0/800

Messages

0 messages
Loading messages...