Skip to main content

KD-AR Stream: Real-Time Data Stream Clustering with Adaptive Radius

Project description

PyPI version License: MIT Python 3.7+

KD-AR Stream

KD-AR Stream is a Python package for real-time data stream clustering using Kd-tree and adaptive radius based methods.

Features

  • Adaptive clustering in streaming data
  • Cluster merging and splitting
  • Supports amount-based and time-based sliding windows
  • Minimal modern plotting for visualization

Installation

pip install kd-ar-stream

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

from kd_ar_stream import KDARStream, KDARStreamConfig, WindowType, load_exclastar

X, y_true = load_exclastar()

config = KDARStreamConfig(N=22, r=0.11, r_threshold=0.16, r_max=0.43)
kdar = KDARStream(config)

for i in range(len(X)):
    kdar.partial_fit(X[i:i+1])

Advanced Usage

import unittest
import numpy as np
from sklearn.metrics.cluster import adjusted_rand_score
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
from kd_ar_stream import KDARStream, KDARStreamConfig, WindowType, load_exclastar

# Load data 
X, y = load_exclastar()

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

#Parameters N, r, r_threshold, r_max, and window_size are parameters of KD-AR Stream
#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
config = KDARStreamConfig(
	N=22,
	r=0.11,
	r_threshold=0.16,
	r_max=0.43,
	window_size=200,
	window_type=WindowType.AMOUNT_BASED,
	verbose=False
)

kdar = KDARStream(config)
timestamps = np.linspace(0, 10, len(X_scaled))

ARI_history = []
for i in range(len(X_scaled)):
	kdar.partial_fit(X_scaled[i:i+1], timestamps[i], np.array([i]))
	
	# CAlculate ARI in each 10 points
	if i % 10 == 0 and i > 0:
		current_labels = kdar.labels_[:i+1]
		if len(np.unique(current_labels[current_labels != -1])) > 1:
			ARI = adjusted_rand_score(y_true[:i+1], current_labels)
			ARI_history.append(ARI)
			kdar.plot_data("Current ARI", ARI)


# Final ARI
y_pred = kdar.labels_
ARI = adjusted_rand_score(y_true, y_pred)
print(f"Final ARI: {ARI:.4f}")

# Final plot
kdar.plot_data("Final ARI", ARI)

Citation

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

Şenol, A., & Karacan, H. (2020). Kd-tree and adaptive radius (KD-AR Stream) based real-time data stream clustering. Journal of the Faculty of Engineering and Architecture of Gazi University, 35(1).

##BibTeX

@article{senol2020kd,
  title={Kd-tree and adaptive radius (KD-AR Stream) based real-time data stream clustering},
  author={Şenol, Ali and Karacan, Hacer},
  journal={Journal of the Faculty of Engineering and Architecture of Gazi University},
  volume={35},
  number={1},
  year={2020}
}

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

kd_ar_stream-1.0.2.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

kd_ar_stream-1.0.2-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file kd_ar_stream-1.0.2.tar.gz.

File metadata

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

File hashes

Hashes for kd_ar_stream-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c1b901686f06ecf3ea8188ba2a4fdc5bd237aca7ee47af927fd27840e97eaa46
MD5 31edf51194fb0d563cfe8c5ea28743ec
BLAKE2b-256 d431a1eed560ab15de0f69bc7fbfc26103fa095c61c20434400ddd27c9349b42

See more details on using hashes here.

File details

Details for the file kd_ar_stream-1.0.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for kd_ar_stream-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 77a3e1e9e34989595a27bfee457c8c9e8e32e5b8615ad0980669ab66abf11440
MD5 fc0fb1ba2b3051fdff97b1cae3e1e021
BLAKE2b-256 e941a82050d6e28e7d8746331a3a3cc48472f172cb31cbf3ec5fdca86cf20fa1

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