You suspect a coin is fair. You encode this as θ∼Beta(10,10) — a prior centered at 0.5 with moderate certainty. You flip the coin 30 times and see 22 heads.
Posterior: Beta(10+22,10+8)=Beta(32,18).
Posterior mean: E[θ∣D]=32+1832=5032=0.64.
Posterior mode (MAP estimate): θ^MAP=50−232−1=4831≈0.646.
MLE (no prior): θ^MLE=22/30=0.733. The prior pulled the estimate toward 0.5.
from scipy import stats
import numpy as np
alpha_prior, beta_prior = 10, 10
k, n = 22, 30
posterior = stats.beta(alpha_prior + k, beta_prior + n - k)
print(f"Posterior mean: {posterior.mean():.3f}")
print(f"95% credible interval: {posterior.interval(0.95)}")