Spectral Bridges
Spectral Bridges is a Python package that implements a novel clustering algorithm combining k-means and spectral clustering techniques. It leverages efficient affinity matrix computation and merges clusters based on a connectivity measure inspired by SVM's margin concept. This package is designed to provide robust clustering solutions, particularly suited for large datasets.
Features
- Spectral Bridges Algorithm: Integrates k-means and spectral clustering with efficient affinity matrix calculation for improved clustering results.
- Scalability: Designed to handle large datasets by optimizing cluster formation through advanced affinity matrix computations.
- Customizable: Parameters such as number of clusters, iterations, and random state allow flexibility in clustering configurations.
- Model selection: Automatic model selection for number of nodes (m) according to a normalized eigengap metric.
Speed
Starting with version 1.0.0, Spectral Bridges not only utilizes FAISS's efficient k-means implementation but also uses a scikit-learn method clone for centroid initialization which is much faster (over 2x improvement).
Installation
You can install the package via pip:
pip install spectral-bridges
Usage
Example
from spectralbridges import SpectralBridges
import numpy as np
# Generate sample data
np.random.seed(0)
X = np.random.rand(100, 10) # Replace with your dataset
# Initialize and fit Spectral Bridges (with a specified number of nodes if needed) and random seed
model = SpectralBridges(n_clusters=5, random_state=42)
# Define range of nodes to evaluate, should be an iterable of integers, or None if n_nodes is already set.
n_nodes_range = [10, 15, 20]
# Find the optimal number of nodes for a given value of clusters
# Modifies the instance attributes, returns a dict
# If n_nodes_range is None, then the model selects using self.n_nodes if not None
mean_ngaps = model.fit_select(X, n_nodes_range)
print("Optimal number of nodes:", model.n_nodes)
print("Dict of mean normalized eigengaps:", mean_ngaps)
# Predict clusters for new data points
new_data = np.random.rand(20, 10) # Replace with new data
predicted_clusters = model.predict(new_data)
print("Predicted clusters:", predicted_clusters)
# With a custom number of nodes
custom_model = SpectralBridges(n_clusters=5, n_nodes=12, p=1) # And a p-bridge affinity
# Fit the model
custom_model.fit(X)
# Predict the same way...
custom_predicted_clusters = custom_model.predict(new_data)
print("Predicted clusters:", custom_predicted_clusters)
Release files for spectral-bridges 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spectral_bridges-1.3.0.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spectral_bridges-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.7 kB
Release files / spectral_bridges-1.3.0.tar.gz
| Download URL | spectral_bridges-1.3.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8d3b915b245a79f729c86b5fc7a05fd256588406734fc23ca448b6b9118b8e4
|
|
BLAKE2b-256 checksum How to use checksums |
99022d97423c4cb47620ec6a5607534452c73306f034bd15e8e6d11d871aafa0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
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 Dec 25, 2024.
Transparency logRelease files / spectral_bridges-1.3.0-py3-none-any.whl
| Download URL | spectral_bridges-1.3.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c02860c7784439abbfbb1d0513c663465dd24648253dfced19b521fd8dff8779
|
|
BLAKE2b-256 checksum How to use checksums |
f1961b0414a102cb9da6abdceff432d60d6aac0334c2c2d69d18d519f896b0f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
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 Dec 25, 2024.
Transparency log