Foundations of Probability in Python
Alexander A. Ramírez M.
CEO @ Synergy Vision
Given that A and B are events in a random experiment, the conditions for independence of A and B are:
Generate a sample that represents 1000 throws of two fair coin flips
from scipy.stats import binom
sample = binom.rvs(n=2, p=0.5, size=1000, random_state=1)
array([1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 2, 0, 1, 1, 1, 0, 0, 2, 2,...
Find repeated data
from scipy.stats import find_repeats
find_repeats(sample)
RepeatedResults(values=array([0., 1., 2.]), counts=array([249, 497, 254]))
Using biased_sample
data generated, calculate the relative frequency of each outcome
from scipy.stats import relfreq
relfreq(biased_sample, numbins=3).frequency
array([0.039, 0.317, 0.644])
$$ $$
Engine | Gear box | |
---|---|---|
Fails | 0.01 | 0.005 |
Works | 0.99 | 0.995 |
$$ $$ $$P(Engine\ fails\ and\ Gear\ box\ fails)=?$$
$$ $$
P_Eng_fail = 0.01
P_GearB_fail = 0.005
P_both_fails = P_Eng_fail*P_GearB_fail
print(P_both_fails)
0.00005
$$P(Jack\ or\ King) = ?$$
$$P(Jack\ or\ King) = \color{red}{P(Jack)}+...$$
$$P(Jack\ or\ King) = \color{red}{\frac{4}{52}}+...$$
$$P(Jack\ or\ King) = P(Jack)+\color{red}{P(King)}$$
$$P(Jack\ or\ King) = \frac{4}{52}+\color{red}{\frac{4}{52}}$$
$$P(Jack\ or\ King) = P(Jack)+P(King)$$
$$P(Jack\ or\ King) = \frac{4}{52}+\frac{4}{52}=\frac{8}{52}=\frac{2}{13}$$
$$P(Jack\ or\ King) = P(Jack)+P(King)$$
$$P(Jack\ or\ King) = \frac{4}{52}+\frac{4}{52}=\frac{8}{52}=\frac{2}{13}$$
$$P(A\ or\ B) = ?$$
$$P(A\ or\ B) = \color{red}{P(A)}+...$$
$$P(A\ or\ B) = P(A) + \color{red}{P(B)}$$
$$P(Jack\ or\ Heart)=?$$
$$P(Jack\ or\ Heart) =\color{red}{P(Jack)}+...$$
$$P(Jack\ or\ Heart) =\color{red}{\frac{4}{52}}+...$$
$$P(Jack\ or\ Heart) =P(Jack)+\color{red}{P(Heart)}\ ...$$
$$P(Jack\ or\ Heart) =\frac{4}{52}+\color{red}{\frac{13}{52}}\ ...$$
$$P(Jack\ or\ Heart) =P(Jack)+P(Heart)...$$
$$P(Jack\ or\ Heart) =\frac{4}{52}+\frac{13}{52}...$$
$$P(Jack\ or\ Heart) =P(Jack)+P(Heart)-\color{red}{P(Jack\ and\ Heart)}$$
$$P(Jack\ or\ Heart) =\frac{4}{52}+\frac{13}{52}-\color{red}{\frac{1}{52}}$$
$$P(Jack\ or\ Heart) =P(Jack)+P(Heart)-P(Jack\ and\ Heart)$$
$$P(Jack\ or\ Heart) =\frac{4}{52}+\frac{13}{52}-\frac{1}{52}=\frac{16}{52}=\frac{4}{13}$$
$$P(A\ or\ B)=?$$
$$P(A\ or\ B)=\color{red}{P(A)}+...$$
$$P(A\ or\ B)=P(A)+\color{red}{P(B)}\ ...$$
$$P(A\ or\ B)=P(A)+P(B)\ ...$$
$$P(A\ or\ B)=P(A)+P(B)-\color{red}{P(A\ and\ B)}$$
$$P(A\ or\ B)=P(A)+P(B)-P(A\ and\ B)$$
P_Jack = 4/52
P_Hearts = 13/52
P_Jack_n_Hearts = 1/52
P_Jack_or_Hearts = P_Jack + P_Hearts - P_Jack_n_Hearts
print(P_Jack_or_Hearts)
0.307692307692
Foundations of Probability in Python