พื้นฐานความน่าจะเป็นด้วย Python
Alexander A. Ramírez M.
CEO @ Synergy Vision

$$ $$
$$\color{red}{P(A\ and\ B)=P(A)P(B)}$$
$$ $$
$$P(A\ and\ B)=P(A)P(B)$$ $$P(A\ and\ B)=\color{blue}{P(A)P(B|A)}$$
$$ $$
$$P(A\ and\ B)=P(A)P(B)$$ $$P(A\ and\ B)=P(A)P(B|A)$$ $$P(B\ and\ A)=\color{red}{P(B)P(A|B)}$$
$$ $$
$$P(A\ and\ B)=P(A)P(B)$$ $$\color{gray}{P(A\ and\ B)}=\color{blue}{P(A)P(B|A)}$$ $$\color{gray}{P(B\ and\ A)}=\color{red}{P(B)P(A|B)}$$
$$ $$
$$P(A\ and\ B)=P(A)P(B)$$ $$\color{gray}{P(A\ and\ B)}=\color{blue}{P(A)P(B|A)}$$ $$\color{gray}{P(B\ and\ A)}=\color{red}{P(B)P(A|B)}$$ $$\color{blue}{P(A)P(B|A)}=\color{gray}{P(A\ and\ B)}=\color{gray}{P(B\ and\ A)}=\color{red}{P(B)P(A|B)}$$
$$ $$
$$P(A\ and\ B)=P(A)P(B)$$ $$\color{gray}{P(A\ and\ B)}=\color{blue}{P(A)P(B|A)}$$ $$\color{gray}{P(B\ and\ A)}=\color{red}{P(B)P(A|B)}$$ $$\color{blue}{P(A)P(B|A)}=\color{gray}{P(A\ and\ B)}=\color{gray}{P(B\ and\ A)}=\color{red}{P(B)P(A|B)}$$ $$\color{blue}{P(A)P(B|A)}=\color{red}{P(B)P(A|B)}$$
$$ $$
$$\color{blue}{P(A)P(B|A)}=\color{red}{P(B)P(A|B)}$$ $$ $$ $$\Longrightarrow \large{\color{red}{P(A|B)} = \frac{\color{blue}{P(A)P(B|A)}}{\color{red}{P(B)}}}$$

$$P(D) = P(V_1\ and\ D) + P(V_2\ and\ D) + P(V_3\ and\ D)$$
$$ $$ $$P(D) = \color{red}{P(V_1\ and\ D)} + \color{blue}{P(V_2\ and\ D)} + \color{#9FAAC3}{P(V_3\ and\ D)}$$
$$\color{red}{P(V_1\ and\ D)} = \color{red}{P(V_1)P(D|V_1)}$$ $$\color{blue}{P(V_2\ and\ D)} = \color{blue}{P(V_2)P(D|V_2)}$$ $$\color{#9FAAC3}{P(V_3\ and\ D)} = \color{#9FAAC3}{P(V_3)P(D|V_3)}$$
$$P(D)=\color{red}{P(V_1)P(D|V_1)}+\color{blue}{P(V_2)P(D|V_2)}+\color{#9FAAC3}{P(V_3)P(D|V_3)}$$

$$P(D)=\color{red}{P(V_1)P(D|V_1)}+\color{blue}{P(V_2)P(D|V_2)}+\color{#9FAAC3}{P(V_3)P(D|V_3)}$$
$$P(A|B) = \frac{P(A)P(B|A)}{P(B)}$$
$$P(A|B) = \frac{P(A)P(B|A)}{P(B)}$$
$$P(V_i|D) = \frac{P(V_i)P(D|V_i)}{P(D)}$$
สูตรของเบย์ส: $$P(A|B) = \frac{P(A)P(B|A)}{P(B)}$$
ความน่าจะเป็นที่ชิ้นส่วนมาจากผู้ผลิต i เมื่อทราบว่าชิ้นส่วนนั้นเสียหาย:
$$P(V_i|D) = \frac{P(V_i)P(D|V_i)}{P(D)}$$ $$ $$ $$P(V_1|D) = \frac{P(V_1)P(D|V_1)}{P(V_1)P(D|V_1)+P(V_2)P(D|V_2)+P(V_3)P(D|V_3)}$$

$$P(V_1|D) = \frac{P(V_1)P(D|V_1)}{P(V_1)P(D|V_1)+P(V_2)P(D|V_2)+P(V_3)P(D|V_3)}$$

$$P(V_1|D) = \frac{\color{red}{P(V_1)P(D|V_1)}}{P(V_1)P(D|V_1)+P(V_2)P(D|V_2)+P(V_3)P(D|V_3)}$$

$$P(V_1|D) = \frac{P(V_1)P(D|V_1)}{\color{red}{P(V_1)P(D|V_1)}+P(V_2)P(D|V_2)+P(V_3)P(D|V_3)}$$

$$P(V_1|D) = \frac{P(V_1)P(D|V_1)}{P(V_1)P(D|V_1)+\color{red}{P(V_2)P(D|V_2)}+P(V_3)P(D|V_3)}$$

$$P(V_1|D) = \frac{P(V_1)P(D|V_1)}{P(V_1)P(D|V_1)+P(V_2)P(D|V_2)+\color{red}{P(V_3)P(D|V_3)}}$$

$$P(V_1|D) = \frac{P(V_1)P(D|V_1)}{P(V_1)P(D|V_1)+P(V_2)P(D|V_2)+P(V_3)P(D|V_3)}$$

$$P(V_1|D) = \frac{P(V_1)P(D|V_1)}{P(V_1)P(D|V_1)+P(V_2)P(D|V_2)+P(V_3)P(D|V_3)}$$

$$P(V_1|D) = \frac{\color{red}{P(V_1)P(D|V_1)}}{...}$$

$$P(V_1|D) = \frac{\color{red}{P(V_1)P(D|V_1)}}{\color{red}{P(V_1)P(D|V_1)}+\color{blue}{P(V_2)P(D|V_2)}+\color{#9FAAC3}{P(V_3)P(D|V_3)}}$$
ชิ้นส่วนอิเล็กทรอนิกส์ชนิดหนึ่งผลิตโดยผู้ผลิต 3 ราย ได้แก่ V1, V2 และ V3
ครึ่งหนึ่งของชิ้นส่วนทั้งหมดผลิตโดย V1 ส่วน V2 และ V3 ผลิตรายละ 25% ความน่าจะเป็นที่ชิ้นส่วนจะเสียหายเมื่อผลิตโดย V1 คือ 1% ส่วน V2 คือ 2% และ V3 คือ 3%
P_V1 = 0.5
P_V2 = 0.25
P_V3 = 0.25
P_D_g_V1 = 0.01
P_D_g_V2 = 0.02
P_D_g_V3 = 0.03
P_Damaged = P_V1 * P_D_g_V1 + P_V2 * P_D_g_V2 + P_V3 * P_D_g_V3
P_V1_g_D = (P_V1 * P_D_g_V1) / P_Damaged # P(V1|D) calculation
print(P_V1_g_D)
ชิ้นส่วนที่สุ่มเลือกมาและพบว่าเสียหายมีความน่าจะเป็นที่ผลิตโดย V1:
0.285714285714
พื้นฐานความน่าจะเป็นด้วย Python