Skip to main content

Bayesian Histogram Anomaly Detection (BHAD)

PyPI version Python 3.12+ License: MIT

A Python implementation of the Bayesian Histogram-based Anomaly Detection (BHAD) algorithm for unsupervised anomaly detection with explainability features.

Overview

BHAD is an explainable anomaly detection method that leverages Bayesian inference and histogram-based modeling to identify outliers in high-dimensional datasets. The algorithm provides both global and local explainability due to its linear structure, making it particularly valuable for applications requiring interpretable results.

Key Features

  • Explainable AI: Provides both global and local explanations for anomaly predictions
  • Bayesian Approach: Uses Bayesian inference for robust uncertainty quantification
  • High-Dimensional Data: Handles high-dimensional datasets effectively
  • Unsupervised Learning: No labeled data required for training
  • Linear Structure: Interpretable model architecture

Installation

Using uv

Install package via uv:

uv venv --python 3.12
uv add bhad

Using pip

python3 -m venv .venv
source .venv/bin/activate
pip install bhad

Quick Start

import numpy as np
import pandas as pd
from bhad.model import BHAD

# Load your data
X = pd.DataFrame(np.random.randn(1000, 10), 
                 columns=[f'feature_{i}' for i in range(10)])

# Create BHAD model with integrated discretization
model = BHAD(contamination=0.01, nbins=None, verbose=False)

# Fit the model and predict anomalies
anomaly_labels = model.fit_predict(X)        # Returns -1 for outliers, 1 for inliers
anomaly_scores = model.decision_function(X)

Documentation

For detailed usage examples, API reference, and tutorials, visit our documentation.

Examples

The package includes Jupyter notebooks with practical examples:

  • Toy_Example.ipynb: Simulated data demonstration
  • Titanic_Example.ipynb: Real-world dataset application

Research & Publications

This implementation is based on the following research papers:

  1. Vosseler, A. (2022): Unsupervised Insurance Fraud Prediction Based on Anomaly Detector Ensembles

  2. Vosseler, A. (2023): BHAD: Explainable anomaly detection using Bayesian histograms

Conference Presentations

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Alexander Vosseler

Citation

If you use BHAD in your research, please cite:

@article{vosseler2022unsupervised,
  title={Unsupervised Insurance Fraud Prediction Based on Anomaly Detector Ensembles},
  author={Vosseler, Alexander},
  journal={Risks},
  volume={10},
  number={7},
  year={2022},
  month={June}
}

Metadata

Release files for bhad 0.2.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bhad 0.2.9.1
File Size Uploaded
bhad-0.2.9.1.tar.gz 23.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bhad 0.2.9.1
File Interpreter ABI Platform
bhad-0.2.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 45.5 kB

Release files / bhad-0.2.9.1.tar.gz

Download URL bhad-0.2.9.1.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c3796921def906c34ccb47896131b626ed3ade983f3689c94dc1e5ecab732675
BLAKE2b-256 checksum
How to use checksums
835e5914f63ea9e22d3b8b3cd698ba1c14492c232f38384051ddeeda4d2da94a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / bhad-0.2.9.1-py3-none-any.whl

Download URL bhad-0.2.9.1-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c52e462a4f9c873efc0e85de1c0809bb00aedc370cbd9f0e46341e388bce33d
BLAKE2b-256 checksum
How to use checksums
41868f28a5d0e9a72274988e3ed5cc457c6b02c5c8a4d5ee30ba9d40ad9ad0ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.2.9.1 This release

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page