Skip to main content

Bayesian Sparse Gaussian Mixture Model implementation in Python

Project description

Bayesian Sparse GMM

Bayesian Sparse Gaussian Mixture Model (GMM) implementation in Python.

Installation

To install the latest release:

pip install bayesian-sparse-gmm

Or for development (editable mode):

git clone https://github.com/Coalyx/bayesian-sparse-gmm.git
cd bayesian-sparse-gmm
pip install -e .

Quick Start

import numpy as np
from sklearn.datasets import make_blobs
from sklearn.preprocessing import StandardScaler
from bayesian_sparse_gmm import BayesianSparseGMM

# Append noise dimensions to true clusters to verify that the model successfully performs feature selection.
rng = np.random.default_rng(42)
X_clean, _ = make_blobs(n_samples=200, centers=3, n_features=2, cluster_std=0.5, random_state=42)
X_noise = rng.normal(loc=0.0, scale=1.0, size=(200, 8))
X = np.hstack([X_clean, X_noise])

# Standardize features to satisfy the zero-mean assumptions in the prior structure.
X = StandardScaler().fit_transform(X)

model = BayesianSparseGMM(
    K_max=5,
    n_iter=300,
    burn_in=100,
    lambda_0=10.0,
    lambda_1=0.05,
    random_state=42,
    verbose=0
)
model.fit(X)

print(f"Number of active clusters: {model.n_clusters_}")
print(f"Selected informative features: {model.selected_features_}")
print(f"Feature inclusion probabilities: {model.feature_probabilities_.round(3)}")

labels = model.predict(X)

Development and Testing

Install development dependencies:

pip install -e ".[dev]"

Run tests using pytest:

pytest

Reference

@article{JMLR:v26:23-0142,
  author  = {Dapeng Yao and Fangzheng Xie and Yanxun Xu},
  title   = {Bayesian Sparse Gaussian Mixture Model for Clustering in High Dimensions},
  journal = {Journal of Machine Learning Research},
  year    = {2025},
  volume  = {26},
  number  = {21},
  pages   = {1--50},
  url     = {http://jmlr.org/papers/v26/23-0142.html}
}

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_sparse_gmm-0.1.1.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

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

bayesian_sparse_gmm-0.1.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file bayesian_sparse_gmm-0.1.1.tar.gz.

File metadata

  • Download URL: bayesian_sparse_gmm-0.1.1.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bayesian_sparse_gmm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3319018575a0215144b88f3592f1880f7181f07f3ccd41bd070f648016e3c95f
MD5 b7fa75ee25e17418bfbc3a255b9c2108
BLAKE2b-256 f4d227f8f0f73e273a80141d53043eabbf6e1cebc59f27799574f133eebe3b48

See more details on using hashes here.

File details

Details for the file bayesian_sparse_gmm-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bayesian_sparse_gmm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1de5b430ab8488670cb510865aa4a2b6a120163e3068ee7c9356789014ab69f
MD5 0b2ee7b5008fec0d037e5f191831fc58
BLAKE2b-256 c39752d829f5c4adcd887533c6b4f91be74dd8a6662583f03ef3916242cc6d13

See more details on using hashes here.

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