Bayesian conjugate models in Python
pip install conjugate-models- Interactive Distribution Explorer for exploring probability distributions with real-time parameter adjustment
- Connection to Scipy Distributions with
distattribute - Built in Plotting with
plot_pdf,plot_pmf, andplot_cdfmethods - Vectorized Operations for parameters and data
- Indexing Parameters for subsetting and slicing
- Generalized Numerical Inputs for any inputs that act like numbers
- Out of box compatibility with
polars,pandas,numpy, and more.
- Out of box compatibility with
- Unsupported Distributions for sampling from unsupported distributions
Many likelihoods are supported including
Bernoulli/BinomialCategorical/MultinomialPoissonNormal(including linear regression)- and many more
- Define prior distribution from
distributionsmodule - Pass data and prior into model from
modelsmodules - Analytics with posterior and posterior predictive distributions
from conjugate.distributions import Beta, BetaBinomial
from conjugate.models import binomial_beta, binomial_beta_predictive
# Observed Data
x = 4
N = 10
# Analytics
prior = Beta(1, 1)
prior_predictive: BetaBinomial = binomial_beta_predictive(n=N, distribution=prior)
posterior: Beta = binomial_beta(n=N, x=x, prior=prior)
posterior_predictive: BetaBinomial = binomial_beta_predictive(
n=N, distribution=posterior
)From here, do any analysis you'd like!
# Figure
import matplotlib.pyplot as plt
fig, axes = plt.subplots(ncols=2)
ax = axes[0]
ax = posterior.plot_pdf(ax=ax, label="posterior")
prior.plot_pdf(ax=ax, label="prior")
ax.axvline(x=x / N, color="black", ymax=0.05, label="MLE")
ax.set_title("Success Rate")
ax.legend()
ax = axes[1]
posterior_predictive.plot_pmf(ax=ax, label="posterior predictive")
prior_predictive.plot_pmf(ax=ax, label="prior predictive")
ax.axvline(x=x, color="black", ymax=0.05, label="Sample")
ax.set_title("Number of Successes")
ax.legend()
plt.show()More examples on in the documentation.
If you are interested in contributing, check out the contributing guidelines
