written by @marc_lelarge
Cost function: for a partition of observations in clusters, the quality of the clustering is given by the following cost function:
k-means algorithm:
Python code:
To focus on brodcasting in the partition step (a), we run the algorithm for a fixed number of iterations (instead of checking convergence criteria).
This code is 60x faster than a naive implementation with a for loop see kmeans_broadcast.ipynb
Applications
Below, we run k-means algorithm on all the colors of all pixels and then replace the original color (on the left) by its corresponding centers (code available in this repo):
public
python
machine learning