Skip to main content

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.

Documentation | PyPI

Features

  • Algorithms: K-Modes clustering for categorical data.
  • Distance Metrics: Hamming, Jaccard, and NG dissimilarity measures.
  • Initialization: Random, Huang, and Cao methods.
  • Optimization: Computationally intensive operations are accelerated using numba.
  • Integration: Supports all ArrayLikes (e.g. numpy arrays, pandas DataFrames, lists of 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 .

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)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kluster_fudge-0.2.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

kluster_fudge-0.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file kluster_fudge-0.2.0.tar.gz.

File metadata

  • Download URL: kluster_fudge-0.2.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for kluster_fudge-0.2.0.tar.gz
Algorithm Hash digest
SHA256 96d4788d97ad0e9ba32b87a109a87c19a04d751721421148e7ea7ed82686df2f
MD5 2d916ac8bfb08820920a482a1ca1d23b
BLAKE2b-256 fcbaa7db957d299c3d69d61c72c209a94a41b5154f4554e2ca1579d4fe5195c0

See more details on using hashes here.

File details

Details for the file kluster_fudge-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: kluster_fudge-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for kluster_fudge-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89033414a344ea524e536f6a398051817c6522eba6c3ac24f77c2fca90f7e39e
MD5 9a07a805b840fc6efda06c3c850bf9a5
BLAKE2b-256 b7faf4c40151b8cbd4a595297b6efb027030832fed6426232ff7f9b88287d589

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