{"categories":[{"label":"Scientific/Engineering","url":"https://skillfed.io/packages/category/scientific-engineering/7"}],"enrichment":{"capability":"K-means clustering with enforced minimum and maximum cluster sizes, using a minimum cost flow algorithm to solve the constrained assignment step.","skillfed_tags":["clustering","constrained-optimization","scikit-learn-compatible"],"use_cases":["Partition customer data into balanced segments for fair resource allocation or stratified analysis","Create evenly-sized geographic clusters or facility assignments where each region must serve a minimum/maximum population","Generate balanced train/test splits or cross-validation folds with size guarantees","Cluster time-series or sensor data where each cluster must contain a minimum viable sample size for statistical validity"],"what_it_does":"k-means-constrained is a variant of k-means clustering that enforces minimum and maximum size constraints on each cluster. Instead of the standard assignment step, it formulates cluster assignment as a minimum cost flow optimization problem solved by ortools' cost-scaling push-relabel algorithm. This ensures that every cluster respects the specified size bounds while minimizing overall distance, making it useful when balanced or size-controlled partitioning is required.\n\nThe package implements a scikit-learn-compatible API and depends on ortools, scipy, numpy, six, and joblib. It trades computational speed for constraint satisfaction: the time complexity is substantially higher than vanilla k-means, scaling as O((n\u00b3c + n\u00b2c\u00b2 + nc\u00b3)log(n+c)) versus O(nc) for standard k-means. The package is actively maintained, supports Python 3.10\u20133.13 with recent free-threading beta support, and has no known vulnerabilities.","worth_installing":"Yes, if you need size-constrained clustering and can tolerate higher computational cost. The package is stable (Production/Stable status), actively maintained, permissively licensed, and has no security vulnerabilities. Install friction is medium due to compiled wheels, but pre-built binaries for modern Python versions (3.10\u20133.13) and multiple platforms are available. Not recommended if you need vanilla k-means performance on large datasets or if cluster size constraints are not a hard requirement."},"id":"k-means-constrained","links":{"html":"https://skillfed.io/packages/k-means-constrained","md":"https://skillfed.io/packages/k-means-constrained.md","pypi":"https://pypi.org/project/k-means-constrained/"},"maintenance":{"status":"active"},"meta":{"latest_release":"2026-07-05","license_spdx":null,"license_treatment":"permissive","name":"k-means-constrained","python_support":"unspecified","summary":"K-Means clustering constrained with minimum and maximum cluster size"},"popularity":{"monthly_downloads":122624,"position":11943,"tier":"top_15000"},"security":{"n_vulnerabilities":0},"version":"0.9.1"}
