kmodes
Python implementations of the k-modes and k-prototypes clustering algorithms for clustering categorical data.
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 kmodesuv
uv add kmodespoetry
poetry add kmodesInstalling 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
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
jenkspyComputes optimal class boundaries for numerical…
permissive · top 15,000 on PyPI
k-means-constrainedK-means clustering with enforced minimum and…
permissive · top 15,000 on PyPI
gmrGaussian Mixture Models for clustering and…
permissive · top 15,000 on PyPI
category-encodersTransforms categorical variables into numeric…
permissive · top 5,000 on PyPI
princePrince implements multivariate exploratory data…
permissive · top 15,000 on PyPI
formulaic-contrastsBuilds arbitrary contrasts for statistical…
permissive · top 15,000 on PyPI
phikPhi_K computes a correlation coefficient that…
permissive · top 5,000 on PyPI
fastclusterPerforms fast hierarchical agglomerative…
copyleft · top 15,000 on PyPI
sktimesktime provides a unified interface for time…
permissive · top 5,000 on PyPI