Skip to main content

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.

Documentation | PyPI

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

Metadata

Release files for kluster-fudge 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kluster-fudge 0.3.1
File Size Uploaded Provenance
kluster_fudge-0.3.1.tar.gz 14.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kluster-fudge 0.3.1
File Interpreter ABI Platform
kluster_fudge-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / kluster_fudge-0.3.1.tar.gz

Download URL kluster_fudge-0.3.1.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f7c74e3c5baccbec6aa3ea32ebe8da7c2fcf5ac52b3a5db8a49b2a0a0f66e308
BLAKE2b-256 checksum
How to use checksums
472169fe4893c57778f0138094a4c0882e16dd94d168eee72cc22cd4656cbb01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / kluster_fudge-0.3.1-py3-none-any.whl

Download URL kluster_fudge-0.3.1-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fee54255838f234c9107b631ae494dbde3222974379b1b34c4461a17d88525d
BLAKE2b-256 checksum
How to use checksums
d9e71b4ee0f182e8729e6b0d5f3758944c0245c68ba061817258a661312730eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Security for kluster-fudge 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page