Skip to main content

Scalable Bayesian feature selection using horseshoe priors with NumPyro/JAX

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bayesian_feature_selection-0.1.0.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bayesian_feature_selection-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file bayesian_feature_selection-0.1.0.tar.gz.

File metadata

File hashes

Hashes for bayesian_feature_selection-0.1.0.tar.gz
Algorithm Hash digest
SHA256 527e980442db2f0815a1d684f665c1b60eeb0226f58045f25458c9be23a28572
MD5 5b75cf47aae2bd7e6931cfa55cf85d25
BLAKE2b-256 d2ce1e7771552385665fc6d1e8a9d11b99b8904233896b39b2d27a5f112cdbcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for bayesian_feature_selection-0.1.0.tar.gz:

Publisher: publish.yml on MacroMagic/bayesian_feature_selection

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bayesian_feature_selection-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bayesian_feature_selection-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bfcd693d694f3c6f2dd0b8d113c4f6fcdda2a840543817eda05b5011df65a70
MD5 99dea43e400bfd58c2208844d96dcd8b
BLAKE2b-256 ec5c5bd4ed57bb7143beadf3c739853af1125b18118f7de31ce6fe76b36a4b7d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page