KD-AR Stream: Real-Time Data Stream Clustering with Adaptive Radius
Project description
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
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)
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.1.tar.gz
(18.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kd_ar_stream-1.0.1.tar.gz.
File metadata
- Download URL: kd_ar_stream-1.0.1.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b647104846ad24422bd7295ff324b9764e7a6f4b0b4ef8cebafd6b976a78edc4
|
|
| MD5 |
e0a118b5070592b101e5aa54ba94657b
|
|
| BLAKE2b-256 |
89d43e54eb1caa92161fab629cfcf456c4e04b002241f205917d99c8c6d9110f
|
File details
Details for the file kd_ar_stream-1.0.1-py3-none-any.whl.
File metadata
- Download URL: kd_ar_stream-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dc804bc64402d9c38e3c6997c08bc1f596ef442e5000fe1bf2289476a050a72
|
|
| MD5 |
b04a8e788ad26a8a3672efdde6e7085f
|
|
| BLAKE2b-256 |
9d7bd0ef926333483d1c3051f1e6e0c95feee5b4f823040cb0b914fee9028400
|