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
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
Supported Models
Many likelihoods are supported including
Bernoulli/BinomialCategorical/MultinomialPoissonNormal(including linear regression)- and many more
Basic Usage
- 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.
Contributing
If you are interested in contributing, check out the contributing guidelines
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.13.0.tar.gz
(22.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file conjugate_models-0.13.0.tar.gz.
File metadata
- Download URL: conjugate_models-0.13.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84be3d7069d70b0835790b15a6d3f78b7108b40b0bd4f5d957d62bb26f16f187
|
|
| MD5 |
c90eb3bb6c4eb5d5c0b23cf5e5c171d1
|
|
| BLAKE2b-256 |
e94c1b4cd18d95f8d828cb1964b08990a634efd1df2d03c5f8c5e4fdd1eeab7b
|
File details
Details for the file conjugate_models-0.13.0-py3-none-any.whl.
File metadata
- Download URL: conjugate_models-0.13.0-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d0154db8ae5d77d1c3ada274e6779cbb8cade243dcae2baacc6f49454376733
|
|
| MD5 |
1d69bcd10a6afbfef009890d07e81f90
|
|
| BLAKE2b-256 |
b7352e4a6448677ef345e815904f15cbc58a33666a36f1800039833e4ca0d63d
|