12 Dependent probability introduction#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/VjLEoo3hIoM/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns

khanacademy

Dependent probability introduction fig 1

bag = set(['Green1', 'Green2', 'Green3', 'Orange1', 'Orange2'])
def P(cond, total_lst):
    cond_lst = list(filter(cond, total_lst))
    return len(cond_lst) / len(total_lst), cond_lst
p_green_st, _ = P(lambda x: x.startswith('Green'), bag)
print(p_green_st)
0.6
bag -= set(['Green1'])
p_green_nd, _ = P(lambda x: x.startswith('Green'), bag)
print(p_green_nd)
0.5
#P(1st Green AND 2nd Green) = P(1st Green) . P(2nd Green | 1st Green)
p_green_st * p_green_nd
0.3