Scalable Bayesian feature selection using horseshoe priors with NumPyro/JAX
Project description
Scalable Bayesian feature selection using horseshoe priors with NumPyro/JAX. Select relevant features from high-dimensional data using a Bayesian GLM with the regularized horseshoe prior, which provides strong shrinkage for irrelevant features while preserving truly relevant signals.
Free software: MIT license
Documentation: https://macromagic.github.io/bayesian_feature_selection/
Features
Horseshoe Prior GLM — Regularized horseshoe prior for automatic feature selection
Multiple GLM Families — Gaussian (regression), Binomial (classification), and Poisson (count data)
MCMC & SVI Inference — Full posterior via NUTS or fast approximation via Stochastic Variational Inference
Flexible Feature Selection — Beta-based, lambda-based, or combined inclusion probabilities
Data Loading & Preprocessing — Built-in CSV loading, train/test splitting, and standardization
CLI Interface — Run experiments from the command line with YAML configuration files
Visualization — Feature importance plots and MCMC diagnostic plots via ArviZ
Quick Start
import numpy as np
from bayesian_feature_selection import HorseshoeGLM, InferenceConfig
# Create synthetic data
rng = np.random.RandomState(42)
n, p = 100, 10
X = rng.randn(n, p)
true_beta = np.array([3.0, -2.0, 0, 0, 1.5, 0, 0, 0, 0, 0])
y = X @ true_beta + rng.randn(n) * 0.5
# Fit model
model = HorseshoeGLM(family="gaussian")
config = InferenceConfig(
method="mcmc", num_warmup=500, num_samples=1000,
num_chains=2, use_gpu=False, progress_bar=False
)
model.fit(X, y, config=config)
# Get selected features
importance = model.get_feature_importance(threshold=0.5)
selected = importance[importance["selected"]]
print(selected[["feature_idx", "beta_mean", "beta_inclusion_prob"]])
# Make predictions
predictions = model.predict(X)
CLI Usage
$ bayesian-fs -c configs/default.yaml
Installation
$ pip install bayesian_feature_selection
For development:
$ pip install -e ".[dev]"
Environment Setup (Python 3.12 + CUDA 12)
Python 3.12 (CPU only)
$ pip install bayesian_feature_selection
This installs JAX ≥ 0.7.0 and NumPyro ≥ 0.15.0 automatically.
Python 3.12 + CUDA 12 (GPU)
Install the package, then upgrade JAX with the CUDA 12 backend:
$ pip install bayesian_feature_selection
$ pip install "jax[cuda12]"
Verify the setup:
import jax
print(jax.devices()) # should show CudaDevice(id=0) when GPU is available
Important version notes
NumPyro ≥ 0.15.0 requires JAX ≥ 0.7.0.
JAX ≥ 0.10.0 removed internal symbols that NumPyro ≤ 0.20.1 depends on; use JAX 0.7.x – 0.9.x until NumPyro releases a compatible update.
The gpu extra (pip install bayesian_feature_selection[gpu]) installs jax[cuda12] and is the recommended way to enable GPU support.
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
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
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 bayesian_feature_selection-0.1.0.tar.gz.
File metadata
- Download URL: bayesian_feature_selection-0.1.0.tar.gz
- Upload date:
- Size: 32.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
527e980442db2f0815a1d684f665c1b60eeb0226f58045f25458c9be23a28572
|
|
| MD5 |
5b75cf47aae2bd7e6931cfa55cf85d25
|
|
| BLAKE2b-256 |
d2ce1e7771552385665fc6d1e8a9d11b99b8904233896b39b2d27a5f112cdbcc
|
Provenance
The following attestation bundles were made for bayesian_feature_selection-0.1.0.tar.gz:
Publisher:
publish.yml on MacroMagic/bayesian_feature_selection
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bayesian_feature_selection-0.1.0.tar.gz -
Subject digest:
527e980442db2f0815a1d684f665c1b60eeb0226f58045f25458c9be23a28572 - Sigstore transparency entry: 1357209034
- Sigstore integration time:
-
Permalink:
MacroMagic/bayesian_feature_selection@4e050a49d8c6c53c5be0a1706cf474f70f3b4e9d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/MacroMagic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4e050a49d8c6c53c5be0a1706cf474f70f3b4e9d -
Trigger Event:
release
-
Statement type:
File details
Details for the file bayesian_feature_selection-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bayesian_feature_selection-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bfcd693d694f3c6f2dd0b8d113c4f6fcdda2a840543817eda05b5011df65a70
|
|
| MD5 |
99dea43e400bfd58c2208844d96dcd8b
|
|
| BLAKE2b-256 |
ec5c5bd4ed57bb7143beadf3c739853af1125b18118f7de31ce6fe76b36a4b7d
|
Provenance
The following attestation bundles were made for bayesian_feature_selection-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on MacroMagic/bayesian_feature_selection
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bayesian_feature_selection-0.1.0-py3-none-any.whl -
Subject digest:
7bfcd693d694f3c6f2dd0b8d113c4f6fcdda2a840543817eda05b5011df65a70 - Sigstore transparency entry: 1357209035
- Sigstore integration time:
-
Permalink:
MacroMagic/bayesian_feature_selection@4e050a49d8c6c53c5be0a1706cf474f70f3b4e9d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/MacroMagic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4e050a49d8c6c53c5be0a1706cf474f70f3b4e9d -
Trigger Event:
release
-
Statement type: