Skip to main content

A versatile two-phase clustering algorithm designed for datasets with both known and exploratory components.

Project description

CLustering In Multiphase Boundaries (CLiMB)

A versatile two-phase clustering algorithm designed for datasets with both known and exploratory components.

Features

  • Two-Phase Clustering: Combines constrained clustering with exploratory clustering to identify both known and novel patterns.
  • Density-Aware: Uses local density estimation to intelligently filter and assign points.
  • Flexible Exploratory Phase: Supports multiple clustering algorithms (DBSCAN, HDBSCAN, OPTICS) through a strategy pattern.
  • Visualization Tools: Built-in 2D and 3D visualization capabilities for cluster analysis.
  • Parameter Tuning: Builder pattern for flexible parameter adjustment.

Installation

pip install climb-astro

Or install from source:

git clone https://github.com/LorenzoMonti/CLiMB.git
cd CLiMB
pip install -e .

Quick Start

import numpy as np
from sklearn.datasets import make_blobs
from sklearn.preprocessing import StandardScaler
from CLiMB.core.CLiMB import CLiMB

# Generate synthetic data
X, y = make_blobs(n_samples=300, centers=3, n_features=3, random_state=42)

# Scale the data
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# Create seed points (optional)
seed_points = np.array([
    X[y == 0].mean(axis=0),
    X[y == 1].mean(axis=0),
    X[y == 2].mean(axis=0)
])
seed_points_scaled = scaler.transform(seed_points)

# Initialize and fit CLiMB
climb = CLiMB(
    constrained_clusters=3,
    seed_points=seed_points_scaled,
    density_threshold=0.2,
    distance_threshold=2.0
)
climb.fit(X_scaled)

# Get cluster labels
labels = climb.get_labels()

# Visualize results (inverse transform to original scale first)
climb.inverse_transform(scaler)
fig = climb.plot_comprehensive_3d(save_path="./3d")
fig2 = climb.plot_comprehensive_2d(save_path="./2d")

Examples

See the examples/ directory for detailed usage examples:

  • simple_example.py: Basic usage with well-defined clusters
  • mixed_data_example.py: Handling mixed data with both convex and non-convex clusters
  • compare_methods.py: Comparing different exploratory clustering methods

How It Works

CLiMB operates in two phases:

  1. Constrained Phase (KBound): A modified K-means that:

    • Uses seed points to guide initial clustering
    • Applies density and distance constraints
    • Prevents centroids from drifting too far using radial thresholds
  2. Exploratory Phase: Uses density-based clustering methods to discover patterns in points not assigned during the first phase.

Use Cases

CLiMB is particularly useful for:

  • Datasets with partially known structure
  • Astronomical data analysis
  • Particle physics clustering
  • Pattern discovery in scientific datasets
  • Data exploration with prior knowledge

Advanced Usage

Using Different Exploratory Algorithms

from CLiMB.core.CLiMB import CLiMB
from CLiMB.exploratory.HDBSCANExploratory import HDBSCANExploratory

# Create HDBSCAN exploratory algorithm
hdbscan = HDBSCANExploratory(min_cluster_size=5, min_samples=3)

# Use it with CLIMB
climb = CLiMB(
    constrained_clusters=3,
    exploratory_algorithm=hdbscan
)

Parameter Tuning with Builder Pattern

climb = CLiMB()
climb.set_density(0.3) \
     .set_distance(2.5) \
     .set_radial(1.0) \
     .set_convergence(0.1)

License

MIT

Citation

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

climb_astro-0.1.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

climb_astro-0.1.3-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file climb_astro-0.1.3.tar.gz.

File metadata

  • Download URL: climb_astro-0.1.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for climb_astro-0.1.3.tar.gz
Algorithm Hash digest
SHA256 988da8741002b82a04a6766bd722d51ca9fd0734921d3c3060ffa0bfc50a8a20
MD5 654f3a6448e131099684593230dbe10f
BLAKE2b-256 84814a55c9748ba160f66a00f38be4ee1e5062e3532fa55b97a47838fd0fe175

See more details on using hashes here.

File details

Details for the file climb_astro-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: climb_astro-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for climb_astro-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2531084366dcfcc26d3ccc75f92930845f0817d835d84f1bd621e9e2f32c400e
MD5 efd01bb0cdbe35ded6c71069471f1de2
BLAKE2b-256 bd3c709e07ec64ffdd0d96d49b379aca2f933230e27a415ae595ea50c95369c3

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