Lesson 13 of 15
Gamma & Beta Distributions
Two Distributions with Flexible Shapes
Gamma Distribution
generalizes the exponential. It is the distribution of the waiting time for events in a Poisson process with rate :
Special case: .
Beta Distribution
lives on and models probabilities and proportions:
Bayesian statistics: the Beta distribution is the conjugate prior for the Bernoulli/Binomial likelihood. After observing successes in trials with a (uniform) prior, the posterior is .
# Beta(2, 5): modeling a conversion rate
alpha, beta = 2, 5
mean = alpha / (alpha + beta)
var = alpha * beta / ((alpha + beta)**2 * (alpha + beta + 1))
print(round(mean, 4)) # 0.2857
print(round(var, 4)) # 0.0255
Your Task
Implement two functions:
gamma_stats(alpha, beta)— prints and ofbeta_stats(alpha, beta)— prints and of
Call both in sequence: first gamma_stats(2.0, 1.0), then beta_stats(2.0, 2.0).
Pyodide loading...
Loading...
Click "Run" to execute your code.