조건부확률(Conditional Probability)

조건부 확률을 설명하기 위해 다이어그램을 사용하면 개념을 쉽게 이해할 수 있습니다. 조건부 확률 ( P(A|B) )는 사건 B가 발생한 조건에서 사건 A가 발생할 확률을 나타냅니다. 이를 다이어그램으로 시각화해 보겠습니다.

\(\)

예시

사건 A와 사건 B가 두 개의 동전 던지기 결과라고 가정해봅시다.

  1. 사건 A: 첫 번째 동전이 앞면일 확률
  2. 사건 B: 두 번째 동전이 앞면일 확률

전체 확률 공간은 모든 가능한 결과(AA, AB, BA, BB)로 구성됩니다. 여기서 조건부 확률 ( P(A|B) )는 두 번째 동전이 앞면일 때 첫 번째 동전이 앞면일 확률입니다.

다이어그램으로 설명하기

  1. 전체 확률 공간을 나타내는 사각형을 그리고, 각 사건을 표시합니다.
  2. 조건부 확률을 나타내기 위해 사건 B가 발생한 조건에서 사건 A의 부분집합을 강조합니다.

Venn 다이어그램을 사용한 조건부 확률 시각화

import matplotlib.pyplot as plt
from matplotlib_venn import venn2

# Define the probabilities
P_A = 0.5  # Probability of event A (first coin is heads)
P_B = 0.5  # Probability of event B (second coin is heads)
P_A_and_B = 0.25  # Probability of both A and B occurring

# Create Venn diagram
plt.figure(figsize=(10, 7))
venn = venn2(subsets=(P_A, P_B, P_A_and_B), set_labels=('Event A', 'Event B'))

# Add labels for additional clarity
plt.text(-0.4, 0.1, f"P(A) = {P_A}", fontsize=12, color='blue')
plt.text(0.4, 0.1, f"P(B) = {P_B}", fontsize=12, color='orange')
plt.text(0, -0.3, f"P(A ∩ B) = {P_A_and_B}", fontsize=12, color='green')

# Add title and display
plt.title("Venn Diagram for Conditional Probability P(A|B)")
plt.show()

이 벤다이어그램은 사건 A와 사건 B의 확률과 이들이 동시에 발생할 확률을 시각적으로 보여줍니다.

조건부 확률 공식

조건부 확률의 수식은 다음과 같습니다:

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

여기서 \( P(A \cap B) \)는 사건 A와 사건 B가 동시에 발생할 확률이며, \( P(B) \)는 사건 B가 발생할 확률입니다.

조건부 확률을 나타내는 다이어그램

이제 조건부 확률을 시각적으로 나타내기 위해 Venn 다이어그램과 사각형 다이어그램을 사용해 보겠습니다.

Venn 다이어그램 예시

import matplotlib.pyplot as plt
from matplotlib_venn import venn2

# Define the probabilities
P_A = 0.5  # Probability of event A
P_B = 0.5  # Probability of event B
P_A_and_B = 0.25  # Probability of both A and B occurring

# Create Venn diagram
plt.figure(figsize=(10, 7))
venn = venn2(subsets=(P_A, P_B, P_A_and_B), set_labels=('Event A', 'Event B'))

# Add title and display
plt.title("Venn Diagram for Conditional Probability P(A|B)")
plt.show()

사각형 다이어그램 예시

import matplotlib.pyplot as plt

# Define the probabilities
P_A = 0.5  # Probability of event A
P_B = 0.5  # Probability of event B
P_A_and_B = 0.25  # Probability of both A and B occurring

# Create rectangle plot
fig, ax = plt.subplots(figsize=(10, 7))

# Draw rectangles for the probabilities
rect1 = plt.Rectangle((0, 0), 1, P_B, edgecolor='orange', facecolor='orange', alpha=0.5, label='P(B)')
rect2 = plt.Rectangle((0, 0), P_A_and_B / P_B, P_B, edgecolor='green', facecolor='green', alpha=0.5, label='P(A ∩ B)')

ax.add_patch(rect1)
ax.add_patch(rect2)

# Add labels for additional clarity
plt.text(0.5, P_B / 2, f"P(B) = {P_B}", fontsize=12, color='black', ha='center')
plt.text(P_A_and_B / (2 * P_B), P_B / 2, f"P(A ∩ B) = {P_A_and_B}", fontsize=12, color='black', ha='center')

# Set limits and labels
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_aspect('equal')
plt.xlabel("Probability Space")
plt.ylabel("Probability")

# Add title and legend
plt.title("Rectangle Diagram for Conditional Probability P(A|B)")
plt.legend()

# Display the plot
plt.show()

이 두 가지 다이어그램은 조건부 확률 \( P(A|B) \)를 시각적으로 설명하는 데 사용됩니다. 첫 번째는 Venn 다이어그램을 사용한 예시이며, 두 번째는 사각형 다이어그램을 사용하여 조건부 확률의 개념을 설명합니다.

댓글 달기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

위로 스크롤