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

# 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-0.0.1.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-0.0.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcmststream-0.0.1.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-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e77eca85f1b1591541d88702aeab1ba5bd5272f22798bd499da6699290d7ba84
MD5 44220a20a99d34df8f2a95bb6e2fd62f
BLAKE2b-256 063a34a904de34150f8becc4fbad400ec940cfb72a67077c03d17c2d8c59e9f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcmststream-0.0.1-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-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f8ad52f28cf66b4dc426be97376884096588b01c20ed4ea757cf74de6fc2676
MD5 7ddb351cab686f7455cb39440b905747
BLAKE2b-256 1070dfa86f3f90f191b3072a3e2237cdf50dea23c6268a2ab8222f49ca43dd5d

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