Bayesian Data Analysis in Python
Michal Oleszak
Machine Learning Engineer
Number of successes in 100 trials:
import numpy as np
np.random.binomial(100, 0.5)
51
np.random.binomial(100, 0.5)
44
Get draws from a binomial:
import numpy as np
np.random.binomial(1, 0.5, size=5)
array([1, 0, 0, 1, 1])
get_heads_prob()
- a custom function
import numpy as np
tosses = np.random.binomial(1, 0.5, size=1000)
print(tosses)
[1 0 0 0 1 1 0 1 1 ... ]
heads_prob = get_heads_prob(tosses)
print(heads_prob)
[0.47815295 0.51679212 0.51684779 ... ]
import matplotlib.pyplot as plt
import seaborn as sns
sns.kdeplot(heads_prob,
shade=True,
label="heads probabilty")
plt.show()
Bayesian Data Analysis in Python