Bayesian Conjugate Models in Python
Project description
Conjugate Models
Bayesian conjugate models in Python
Installation
pip install conjugate-models
Features
- Connection to Scipy Distributions with
dist
attribute - Built in Plotting with
plot_pdf
andplot_pmf
methods - Vectorized Operations for parameters and data
- Indexing Parameters for subsetting and slicing
- Generalized Numerical Inputs for inputs other than builtins and numpy arrays
- Unsupported Distributions for sampling from unsupported distributions
Supported Models
Many likelihoods are supported including
Bernoulli
/Binomial
Categorical
/Multinomial
Poisson
Normal
(including linear regression)- and many more
Basic Usage
- Define prior distribution from
distributions
module - Pass data and prior into model from
models
modules - Analytics with posterior and posterior predictive distributions
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.3.1.tar.gz
(10.0 kB
view hashes)
Built Distribution
Close
Hashes for conjugate_models-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c88212390edde4e752ada5198276a77ff9b569fc95ee6bc03ba6658b1b9b00f9 |
|
MD5 | d18785023020d99fba35c453bc8a1b9e |
|
BLAKE2b-256 | d53437deba334314fb97e4719a4ac40f397f3f01f33775adb15300e934adcff8 |