A Python library for clustering categorical data using K-Modes with various distance metrics.
Project description
KlusterFudge
A Python library for clustering categorical data using the K-Modes algorithm. It supports multiple initialization methods and distance metrics, optimized with numba for performance.
Features
- Algorithms: K-Modes clustering for categorical data
- GPU Acceleration: Optional PyTorch-based GPU acceleration via
KModesGPU - Distance Metrics: Hamming, Jaccard, and NG dissimilarity measures
- Initialization: Random, Huang, and Cao methods
- Optimization: CPU operations accelerated with
numba, GPU operations with PyTorch - Integration: Supports all ArrayLikes (numpy arrays, pandas DataFrames, lists, etc.)
Installation
Install KlusterFudge via pip:
pip install kluster-fudge
Or install from source:
git clone https://github.com/ethqnol/KlusterFudge.git
cd KlusterFudge
pip install .
GPU Acceleration (Optional)
For GPU acceleration, install PyTorch:
pip install torch
See PyTorch installation guide for CUDA/ROCm support.
Quick Start
import pandas as pd
from kluster_fudge import KModes
# 1. Load Data
df = pd.DataFrame({
'color': ['red', 'blue', 'red', 'green', 'blue', 'green'],
'size': ['small', 'large', 'small', 'large', 'medium', 'medium'],
'shape': ['circle', 'square', 'circle', 'square', 'triangle', 'triangle']
})
# 2. Initialize Model
model = KModes(
n_clusters=2,
init_method='cao',
dist_metric='hamming',
random_state=42
)
# 3. Fit and Predict
clusters = model.fit_predict(df)
print("Cluster Labels:", clusters)
GPU Acceleration
For large datasets, use KModesGPU for significant speedups (unless using NG dissimilarity):
from kluster_fudge import KModesGPU
import numpy as np
# Large dataset
X = np.random.randint(0, 10, size=(100000, 20))
# GPU model (auto-detects CUDA/MPS/CPU)
model_gpu = KModesGPU(n_clusters=5, n_init=5, random_state=42)
model_gpu.fit(X)
# 3-6x faster than CPU on typical datasets
Performance: On a 100k sample dataset, GPU achieves ~3.2x speedup on Apple Silicon (MPS) and up to 6x on CUDA GPUs.
Comparisons & Benchmarks
See benchmarks/benchmark_metrics.py
| Metric | Init | Time (s) |
|---|---|---|
| jaccard | cao | 0.051574 |
| jaccard | huang | 0.051677 |
| hamming | cao | 0.052091 |
| hamming | huang | 0.052477 |
| ng | huang | 0.055497 |
| ng | cao | 0.055761 |
| jaccard | random | 0.569103 |
| ng | random | 1.325702 |
| hamming | random | 3.131030 |
(Run on 5000 samples, 20 features, 10 categories)
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 kluster_fudge-0.3.0.tar.gz.
File metadata
- Download URL: kluster_fudge-0.3.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e9504c810b05b7c633f37b49e3fb774d3df4fa04b405e357c8a8a9dd9781098
|
|
| MD5 |
d30d17cd310767f487481b64027e5ab5
|
|
| BLAKE2b-256 |
092a5f67bcb19a694abef4fe1da113120c5f432dc77dca156ca4ae36a54c094a
|
File details
Details for the file kluster_fudge-0.3.0-py3-none-any.whl.
File metadata
- Download URL: kluster_fudge-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3086f00d7cd46d72e13928eeaa123b9517fee43400409054df3e7d94ff2f784
|
|
| MD5 |
528d6bb46267674ebe05e4d663973b0e
|
|
| BLAKE2b-256 |
dd2fea220e8eba57c75051171df332ad14e742f9efed5d92f2ff9325d8ed7e44
|