skillfed

kmodes

Python implementations of the k-modes and k-prototypes clustering algorithms for clustering categorical data.

kmodes v0.12.2 561.9K downloads/30d#5,992 on PyPI1,285
Permissive license MIT DORMANT released

What it is and what it does

kmodes provides Python implementations of k-modes and k-prototypes clustering, specialized for categorical and mixed data types. Unlike k-means, which clusters numerical data by Euclidean distance, k-modes clusters categorical variables by counting matching categories between points. k-prototypes extends this to handle datasets with both numerical and categorical features. The library mirrors scikit-learn's clustering API, making it familiar to users of that ecosystem.

The package relies on numpy for computation and supports parallel execution via joblib for multiple initialization runs. It includes initialization strategies such as Huang's method and density-based approaches. All runtime dependencies (numpy, scikit-learn, scipy, joblib) are standard data-science libraries with low installation friction.

Use it for:

  • Cluster customer records with mixed demographic (categorical) and behavioral (numerical) attributes.
  • Segment product categories or survey responses where most features are discrete or nominal.
  • Analyze categorical genomic or medical data where Euclidean distance is not meaningful.
  • Reduce dimensionality or find patterns in text-encoded or one-hot-encoded feature sets.
  • Benchmark or compare k-modes results against k-means on datasets with predominantly categorical features.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Implements k-modes and k-prototypes clustering algorithms for categorical and mixed numerical/categorical data, with a scikit-learn-compatible interface.

Yes, if you need to cluster categorical or mixed-type data and want a scikit-learn-compatible interface. The low install friction and permissive license make it a straightforward choice. However, the dormant maintenance status (last release 2022-09-06) warrants checking compatibility with your current numpy and scikit-learn versions before committing to production use.

Install

kmodes on PyPI

pip

pip install kmodes

uv

uv add kmodes

poetry

poetry add kmodes

Installing kmodes

Before you install

Low friction install with standard dependencies (numpy, scikit-learn, scipy, joblib). Maintenance is dormant—last release was 2022-09-06, though the repository remains active with recent commits and no archived status.

License in practice

MIT license permits commercial and private use with minimal restrictions; you must include the license text in distributions.

Quickstart

pip install kmodes

import numpy as np
from kmodes.kmodes import KModes

data = np.random.choice(20, (100, 10))
km = KModes(n_clusters=4, init='Huang', n_init=5, verbose=1)
clusters = km.fit_predict(data)

Input data must have consistent data types within columns; NaN values are not accepted and must be handled before clustering.

Verify before relying

  • Whether the dormant maintenance status affects compatibility with current numpy/scikit-learn versions.
  • Performance characteristics and scalability limits for large datasets relative to alternatives.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 4 — numpy, scikit-learn, scipy, joblib
Maintenance dormant — 1,438 days since the last release
Last repo commit
First released
Downloads 561,891/month — #5,992 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: kmodes-0.12.2-py2.py3-none-any.whl

Development Status :: 3 - AlphaIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Scientific/Engineering

Tags

categorical clusteringk-modes algorithmk-prototypes mixed datacategorical data clusteringnon-numeric clusteringmode-based clusteringscikit-learn clustering alternative
clusteringcategorical-datascikit-learn-compatible

More Scientific/Engineering packages

Further reading