Skip to main content

Spectral Bridges clustering algorithm

Project description

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

import spectralbridges as sb
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 = sb.SpectralBridges(n_clusters=5, random_state=42)

# Define range of nodes to evaluate, iterable or a single int
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
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 = sb.SpectralBridges(n_clusters=5, n_nodes=12)

# 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)

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

spectral_bridges-1.2.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

spectral_bridges-1.2.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file spectral_bridges-1.2.1.tar.gz.

File metadata

  • Download URL: spectral_bridges-1.2.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for spectral_bridges-1.2.1.tar.gz
Algorithm Hash digest
SHA256 59fd547a04659f0cd75146176660eaf18e454e0662e05365d47a9f671989470d
MD5 2a59d10b73c0420f5d1289aef599db91
BLAKE2b-256 17b6b783a6e77c2d17b7fa57f629faeae4f9e11d02b6640c2968c254a977e89b

See more details on using hashes here.

File details

Details for the file spectral_bridges-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for spectral_bridges-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13e59c7a162fad6edd7329fefd1edc91e30e12d6678093aede6fc126e0686c22
MD5 608ef53deb7174ccc72eaf94192e81ae
BLAKE2b-256 13da00fcaac1e29639c658c64d023b59adf35d50c603aa6a65ff5e9bb66531a4

See more details on using hashes here.

Supported by

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