Bayesian Data Analysis in Python
Michal Oleszak
Machine Learning Engineer
Our prior belief: heads less likely
Some choices are better than others!
numpy
.get_heads_prob()
from Chapter 1:def get_heads_prob(tosses):
num_heads = np.sum(tosses)
# prior: Beta(1,1)
return np.random.beta(num_heads + 1, len(tosses) - num_heads + 1, 1000)
Simulation
numpy
:draws = np.random.beta(2, 4, 1000)
array([0.05941031, ..., 0.70015975])
sns.kdeplot(draws)
Calculation
head_prob posterior_prob
0 0.00 0.009901
1 0.01 0.003624
... ...
10199 0.99 0.003624
10200 1.00 0.009901
sns.lineplot(df["head_prob"], df["posterior_prob"])
Bayesian Data Analysis in Python