Skip to main content

Bayesian Feature Selection

https://img.shields.io/pypi/v/bayesian_feature_selection.svg https://github.com/MacroMagic/bayesian_feature_selection/actions/workflows/ci.yml/badge.svg Documentation Status

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.

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.

Metadata

Release files for bayesian-feature-selection 0.1.0

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

Source distribution (sdist)

Source distribution for bayesian-feature-selection 0.1.0
File Size Uploaded
bayesian_feature_selection-0.1.0.tar.gz 32.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bayesian-feature-selection 0.1.0
File Interpreter ABI Platform
bayesian_feature_selection-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.9 kB

Release files / bayesian_feature_selection-0.1.0.tar.gz

Download URL bayesian_feature_selection-0.1.0.tar.gz
Size 32.8 kB
Tags Source
SHA-256 checksum
How to use checksums
527e980442db2f0815a1d684f665c1b60eeb0226f58045f25458c9be23a28572
BLAKE2b-256 checksum
How to use checksums
d2ce1e7771552385665fc6d1e8a9d11b99b8904233896b39b2d27a5f112cdbcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release files / bayesian_feature_selection-0.1.0-py3-none-any.whl

Download URL bayesian_feature_selection-0.1.0-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bfcd693d694f3c6f2dd0b8d113c4f6fcdda2a840543817eda05b5011df65a70
BLAKE2b-256 checksum
How to use checksums
ec5c5bd4ed57bb7143beadf3c739853af1125b18118f7de31ce6fe76b36a4b7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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