Foundations of Probability in Python - Part 2
Foundations of Probability in Python - Part 2
probabilities of two
events
F O U N D AT I O N S O F P R O B A B I L I T Y I N P Y T H O N
Alexander A. Ramírez M.
CEO @ Synergy Vision
Independence
Given that A and B are events in a random experiment, the conditions for independence of A
and B are:
1. The order in which A and B occur does not a ect their probabilities.
array([1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 2, 0, 1, 1, 1, 0, 0, 2, 2,...
4
P (Jack or King) = + ...
52
4 4
P (Jack or King) = +
52 52
4 4 8 2
P (Jack or King) = + = =
52 52 52 13
4 4 8 2
P (Jack or King) = + = =
52 52 52 13
4
P (Jack or Heart) = + ...
52
4 13
P (Jack or Heart) = + ...
52 52
4 13
P (Jack or Heart) = + ...
52 52
4 13 1
P (Jack or Heart) = + −
52 52 52
4 13 1 16 4
P (Jack or Heart) = + − = =
52 52 52 52 13
0.307692307692
Alexander A. Ramírez M.
CEO @ Synergy Vision
Dependent events
4
P (Jack) = ≃ 7.69%
52
3
P (Jack) = ≃ 5.88%
51
P (A and B)
P (B∣A) =
P (A)
P (Red∣Jack) =?
2
P (Jack and Red) 52
P (Red∣Jack) = = 4
P (Jack) 52
2
P (Jack and Red) 52 2 1
P (Red∣Jack) = = 4
= =
P (Jack) 52
4 2
2
P (Jack and Red) 52 2 1
P (Red∣Jack) = = 4
= =
P (Jack) 52
4 2
print(P_Red_given_Jack)
0.5
P (Jack∣Red) =?
2
P (Red and Jack) 52
P (Jack∣Red) = = 26
P (Red) 52
2
P (Red and Jack) 52 2 1
P (Jack∣Red) = = 26
= =
P (Red) 52
26 13
2
P (Red and Jack) 52 2 1
P (Jack∣Red) = = 26
= =
P (Red) 52
26 13
print(P_of_Jack_given_Red)
0.0769230769231
Alexander A. Ramírez M.
CEO @ Synergy Vision
Deck of cards example
P (F ace card) =?
P (F ace card) = P (Club and F ace card) + P (Spade and F ace card) + ...
P (F ace card) = P (Club and F ace card) + P (Spade and F ace card)+
P (F ace card) = P (Club and F ace card) + P (Spade and F ace card)+
P_Club_n_FC = 3/52
P_Spade_n_FC = 3/52
P_Heart_n_FC = 3/52
P_Diamond_n_FC = 3/52
0.230769230769
P (D) =?
Half of the parts are produced by V1, and V2 and V3 each produce 25%. The probability of a
part being damaged given that it was produced by V1 is 1%, while it's 2% for V2 and 3% for V3.
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
0.0175
Alexander A. Ramírez M.
CEO @ Synergy Vision
FOUNDATIONS OF PROBABILITY IN PYTHON
P(A and B) for independent events
P (A)P (B∣A)
⟹ P (A∣B) =
P (B)
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
P (V1 )P (D∣V1 )
P (V1 ∣D) =
...
P (V1 )P (D∣V1 )
P (V1 ∣D) =
P (V1 )P (D∣V1 ) + P (V2 )P (D∣V2 ) + P (V3 )P (D∣V3 )
Half of the parts are produced by V1, and V2 and V3 each produce 25%. The probability of a
part being damaged given that it was produced by V1 is 1%, while it's 2% for V2 and 3% for V3.
Given that the part is damaged, what is the probability that it was manufactured by V1?
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
0.285714285714