scikit-bayes
scikit-bayes adds Bayesian network classifiers to scikit-learn. Every model follows the scikit-learn estimator API, so it works in pipelines, cross-validation and grid search, and takes tables that mix continuous, categorical and binary attributes, including pandas DataFrames with columns of strings or of category dtype. Counting and prediction run in compiled Numba kernels.
Models
MixedNB: Naive Bayes with Gaussian, categorical and Bernoulli attributes in one model.AnDE: Averaged n-Dependence Estimators (AODE, A2DE), pooled with the arithmetic or the geometric mean.WeightedAnDE: AnDE with discriminative weights, one per component or one per factor of each component (the weighted CCBN of Zaidi et al., 2017), at four levels of granularity, fitted jointly or one component at a time (which gives the AnDEw of FedAnDE).AnJEandALR: Averaged n-Join Estimators and Accelerated Logistic Regression as defined by Zaidi et al. (2016), trained by default with the protocol of the paper.GaussianAnJEandGaussianALR: AnJE and ALR built on the factors of the SPnDEs, so that continuous attributes keep Gaussian conditionals, as in HAODE.TAN: Tree Augmented Naive Bayes, with a Chow-Liu tree of attribute dependencies.KDB: K-Dependence Bayesian classifier, in which every attribute has at most k attribute parents chosen by conditional mutual information.WeightedTANandWeightedKDB: TAN and KDB with discriminative weights on their parameters (the weighted CCBN of Zaidi et al., 2017), which correct the dependencies the structure leaves out.MDLPDiscretizerandDecisionTreeDiscretizer: supervised discretization of continuous attributes, to place before a model in a pipeline. Every model also takes the MDL discretization of Fayyad and Irani directly, asstrategy="mdlp", andcontinuous_children="discretized"runs AnDE, TAN and KDB on the discretized attributes, as in the original works, instead of with Gaussian children.
Quick start
import numpy as np
from skbn import MixedNB, AnDE
# A Gaussian, a binary and a categorical column; the types are inferred
X = np.array([[1.5, 0, 2], [-0.5, 1, 0], [2.1, 1, 1], [-1.2, 0, 2]])
y = np.array([0, 1, 1, 0])
clf = MixedNB()
clf.fit(X, y)
print(clf.predict([[0.5, 1, 1]])) # [1]
# XOR, which Naive Bayes cannot learn
X_xor = np.array([[-1, -1], [-1, 1], [1, -1], [1, 1]])
y_xor = np.array([0, 1, 1, 0])
clf = AnDE(n_dependence=1, n_bins=2)
clf.fit(X_xor, y_xor)
print(clf.predict(X_xor)) # [0 1 1 0]
Installation
pip install scikit-bayes
The development version installs from GitHub:
pip install git+https://github.com/ptorrijos99/scikit-bayes.git
The models run in Numba kernels that are compiled the first time each model is used and then cached on disk, so the first fit after installing takes from a couple of seconds (MixedNB) to some ten (AnDE), and later sessions start in a fraction of a second. To pay that once and check the installation:
python -m skbn
It prints the versions, fits and evaluates every model on the iris data and verifies the results.
Documentation
- User guide: how each model is defined and estimated, and how to choose its parameters.
- API reference: parameters, attributes and methods of every class.
- Example gallery: what each model captures, shown on small datasets with plots.
Development
The development environments are managed with pixi:
# Run tests
pixi run test
# Run linter
pixi run lint
# Build documentation
pixi run build-doc
# Activate development environment
pixi shell -e dev
Citation
If you use scikit-bayes in a scientific publication, please cite:
@software{scikit_bayes,
author = {Torrijos, Pablo and Alcarria Laserna, {\'O}scar and G{\'a}mez, Jos{\'e} A. and Puerta, Jos{\'e} M.},
title = {scikit-bayes: Bayesian Network Classifiers for Python},
year = {2026},
doi = {10.5281/zenodo.23950884},
url = {https://github.com/ptorrijos99/scikit-bayes}
}
The DOI always resolves to the latest version; every release also has its own DOI on Zenodo (1.3.0: 10.5281/zenodo.23950885). The same information is in CITATION.cff, which GitHub shows as "Cite this repository".
References
- Webb, G. I., Boughton, J., & Wang, Z. (2005). Not so naive Bayes: Aggregating one-dependence estimators. Machine Learning, 58(1), 5-24.
- Flores, M. J., Gámez, J. A., Martínez, A. M., & Puerta, J. M. (2009). GAODE and HAODE: Two proposals based on AODE to deal with continuous variables. ICML '09, 313-320.
- Zaidi, N. A., Webb, G. I., Carman, M. J., Petitjean, F., & Cerquides, J. (2016). ALR^n: Accelerated higher-order logistic regression. Machine Learning, 104(2-3), 151-194.
- Zaidi, N. A., Webb, G. I., Carman, M. J., Petitjean, F., Buntine, W., Hynes, M., & De Sterck, H. (2017). Efficient parameter learning of Bayesian network classifiers. Machine Learning, 106(9-10), 1289-1329.
License
BSD-3-Clause. See LICENSE for details.
Metadata
Release files for scikit-bayes 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scikit_bayes-1.4.0.tar.gz | 411.8 kB | With provenance | Details for scikit_bayes-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scikit_bayes-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for scikit_bayes-1.4.0-py3-none-any.whl |
Total release size: 639.8 kB
Release files / scikit_bayes-1.4.0.tar.gz
| Download URL | scikit_bayes-1.4.0.tar.gz |
|---|---|
| Size | 411.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e1fd988ce65e2f96f824603aec4b032020c8587493574c8d1fc5de38e4efcf5
|
|
BLAKE2b-256 checksum How to use checksums |
752b13ec434cc68d3b10f420dbadfe054180830779cc4a8bdb6b9021b16b0362
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logRelease files / scikit_bayes-1.4.0-py3-none-any.whl
| Download URL | scikit_bayes-1.4.0-py3-none-any.whl |
|---|---|
| Size | 228.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb88c593e09dcb5b83103a18f13b787cf3524bf536c86c5a351e941c2ccd43b4
|
|
BLAKE2b-256 checksum How to use checksums |
9f0527bee127b9b4e6ca851efe9f971f22dfeefc3c55feaae2f4a02a07285a56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logSecurity for scikit-bayes 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for scikit_bayes-1.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.