============================================================
k-means clustering is a method of vector quantization, originally from signal processing, that is popular for cluster analysis in data mining. k-means clustering aims to partition n observations into k clusters in which each observation belongs to the cluster with the nearest mean, serving as a prototype of the cluster. This results in a partitioning of the data space into Voronoi cells.
source: wikipedia
See the algorithm in action here.
media\ media files
kmeans.css CSS stylesheet
index.html webpage demonstrating the algorithm
kmeans.js JavaScript file with the source code for the algorithm visualization
README.md README file that appears on the website's github page
Data are randomly generated x,y-coordinates between 0 and the width/height of the canvas.
- The algorithm is initialized with n random points, along with k randomly generated 'means' (centroid) within the data domain.
- When the algorithm starts, each point is assigned the color of the closest centroid, forming k clusters. Closest is defined as the smallest Euclidean distance between two points.
- The centroids are moved to the center of the cluster.
- Steps 2 and 3 are repeated until the maximum number of iterations is reached.