Ckmeans is a function to cluster a one-dimensional array of floats into k
optimal clusters.
Optimal
here means that the standard deviation inside each cluster is minimized.
Ckmeans was developed by Haizhou Wang and Mingzhou Song.
This code follows directly from Tom MacWright's code in simple-statistics and David Schnurr's code in d3-scale-cluster.
Please use this code in any way you wish, with or without attribution. It's licensed WTFPL.
If you'd rather use the original C++ code via a cython wrapper, check out rocketrip/ckmeans.
2024 update: I recommend ckmeans_py (available on pyPI) which wraps an efficient rust version of this algorithm
In 2022 ckmeans picked up a citation!