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
import numpy as np
from sklearn.metrics.cluster import adjusted_rand_score
from sklearn.preprocessing import MinMaxScaler
from kd_ar_stream import KDARStream, KDARStreamConfig, WindowType, load_exclastar
# Load data
X, y_true = 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))
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:
kdar.plot_data()
# 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()
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}
}
Metadata
Release files for kd-ar-stream 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kd_ar_stream-1.0.8.tar.gz | 18.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kd_ar_stream-1.0.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.8 kB
Release files / kd_ar_stream-1.0.8.tar.gz
| Download URL | kd_ar_stream-1.0.8.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4df144bd81a238e51fd7e2967188967d3522f9b117c3862c45889e57011bb9e
|
|
BLAKE2b-256 checksum How to use checksums |
5c9ba5cc32e95fc84f7b69e86601342a10d3a12d743880d56d208bb0ca19706c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / kd_ar_stream-1.0.8-py3-none-any.whl
| Download URL | kd_ar_stream-1.0.8-py3-none-any.whl |
|---|---|
| Size | 17.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7969d8fb9e7554907840a231da55c7b6d077e4b126315d821f26f34388a33856
|
|
BLAKE2b-256 checksum How to use checksums |
fbbb7798316cb2aad74dcebf71ae9f397fbaa50271ae5d54b99e6b503de493ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|