Skip to main content

MCMSTStream: applying minimum spanning tree to KD-tree-based micro-clusters to define arbitrary-shaped clusters in streaming data

Project description

PyPI version License: MIT Python 3.7+

MCMSTStream

MCMSTStream is a streaming clustering algorithm based on Minimum Spanning Trees (MST) and KD-Tree–based micro-clusters.

Features

✨ Features

✔ Online streaming clustering
✔ Sliding window model
✔ KD-Tree accelerated micro-cluster formation
✔ Macro-cluster discovery via Minimum Spanning Tree
✔ Noise & outlier handling
✔ Visualization utilities
✔ Scikit-learn–compatible API (fit, partial_fit, predict, get_params, set_params)
✔ Supports incremental, real-time data processing

Installation

pip install mcmststream

Parameters

If you want to use amount-based sliding window assign WindowType.AMOUNT_BASED If you want to use time based sliding window, assign WindowType.TIME_BASED N: int -> Minimum number of points to form a cluster r: float -> Initial cluster radius r_threshold: float -> Radius increase/decrease threshold r_max: float -> Maximum cluster radius window_type: WindowType -> {WindowType.AMOUNT_BASED,WindowType.TIME_BASED window_size: int -> For amount-based: number of points in window verbose: bool {True, False}

Usage

import numpy as np
from sklearn.metrics.cluster import adjusted_rand_score
from sklearn.preprocessing import MinMaxScaler
from mcmstream import MCMSTStream, load_exclastar

# Load data 
X, y_true = load_exclastar()

# Normalize
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)
np.random.seed(42)

# Initialize with history keeping enabled
clusterer = MCMSTStream(
    W=270,  
    n_micro=2, 
    N=2,   
    r=0.14, 
    random_state=42,
    keep_history=True  # Enable history tracking
)
for i, point in enumerate(X_scaled):
        label = clusterer.partial_fit(point)
        
        # Visualize periodically
        if i % 20 == 0 and i > 0:
            print(f"\nStep {i}:")
            print(f"  Current label for this point: {label}")
            print(f"  Micro-clusters: {len(clusterer.micro_clusters)}")
            print(f"  Macro-clusters: {len([m for m in clusterer.macro_clusters if m['active']])}")
            if clusterer.keep_history:
                hist_labels = np.array(clusterer.history_labels_)
                print(f"  History labels (unique): {np.unique(hist_labels)}")
            
            clusterer.visualize(title=f"Step {i}")
    
ARI=adjusted_rand_score(y_true,clusterer.history_labels_)
print("ARI=%0.4f"%ARI)

Visualization

The package includes a built-in visualization function:

clusterer.visualize(title="MCMSTStream Clustering Result")

Evaluation

Calculates:

Silhouette Score

Calinski-Harabasz Index

Davies-Bouldin Index

ARI, NMI, V-Measure (if true labels provided)

metrics = clusterer.evaluate(true_labels=y_true)
print(metrics)

Citation

If you use this algorithm in research, please cite the corresponding paper.

Erdinç, B., Kaya, M., & Şenol, A. (2024). MCMSTStream: applying minimum spanning tree to KD-tree-based micro-clusters to define arbitrary-shaped clusters in streaming data. Neural Computing and Applications, 36(13), 7025-7042.

BibTeX

@article{erdincc2024mcmststream,
  title={MCMSTStream: applying minimum spanning tree to KD-tree-based micro-clusters to define arbitrary-shaped clusters in streaming data},
  author={Erdin{\c{c}}, Berfin and Kaya, Mahmut and {\c{S}}enol, Ali},
  journal={Neural Computing and Applications},
  volume={36},
  number={13},
  pages={7025--7042},
  year={2024},
  publisher={Springer}
}

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

mcmststream-1.0.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

mcmststream-1.0.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file mcmststream-1.0.0.tar.gz.

File metadata

  • Download URL: mcmststream-1.0.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mcmststream-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fd044d75ec7eb2cd22cd870b46afcf28c5448115cdced64907ad46c35b677331
MD5 a8e42e285e2e1709ff5fa2c507766d18
BLAKE2b-256 589687996116455b6e749c890fc6dea64936143546145b48c0b9a3de7a83b1a2

See more details on using hashes here.

File details

Details for the file mcmststream-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mcmststream-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mcmststream-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36021b54f84bc5ed946a187e6452aaada7c99c11d9acf9237b4416812655c048
MD5 60fcd7b18f35f2e472c4a523f2183e27
BLAKE2b-256 d11bbdf583ae960bff9507a6b47be38391d2cc2a4fbb39638b8b4f5281f602e2

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