Bayesian Conjugate Models in Python
Project description
conjugate priors
Bayesian conjugate models in Python
Installation
pip install conjugate-models
Basic Usage
from conjugate.distributions import Beta, BetaBinomial
from conjugate.models import binomial_beta, binomial_beta_posterior_predictive
# Observed Data
X = 4
N = 10
# Analytics
prior = Beta(1, 1)
prior_predictive: BetaBinomial = binomial_beta_posterior_predictive(n=N, beta=prior)
posterior: Beta = binomial_beta(n=N, x=X, beta_prior=prior)
posterior_predictive: BetaBinomial = binomial_beta_posterior_predictive(n=N, beta=posterior)
# 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
conjugate_models-0.1.6.tar.gz
(8.6 kB
view hashes)
Built Distribution
Close
Hashes for conjugate_models-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba6f0a4328743280a5a89a980de13e23163dd27d79eeb757db9e0e27c084f103 |
|
MD5 | 3ca6951641d85053203d6b1444f428c5 |
|
BLAKE2b-256 | 6e79355b4948e0a275d90d641d8700677515f121d794c1baf4a0aa9b9e5e9101 |