Jupyter Snippet CB2nd 03_bayesian
Jupyter Snippet CB2nd 03_bayesian
7.3. Getting started with Bayesian methods
import numpy as np
import scipy.stats as st
import matplotlib.pyplot as plt
%matplotlib inline
def posterior(n, h, q):
return (n + 1) * st.binom(n, q).pmf(h)
n = 100
h = 61
q = np.linspace(0., 1., 1000)
d = posterior(n, h, q)
fig, ax = plt.subplots(1, 1)
ax.plot(q, d, '-k')
ax.set_xlabel('q parameter')
ax.set_ylabel('Posterior distribution')
ax.set_ylim(0, d.max() + 1)