Visualizing K-Means algorithm

K-Means is a popular and simple clustering algorithm. K-means takes an unsupervised approach, which means that the input data points are not labelled, and the algorithm figures out the patterns on its own.

Steps to execute kmeans

  1. Initialization: K centroids are randomly initialized
  2. Assignment step: Each of the N data-points is assigned to the nearest cluster (centroid)
  3. Update step: When all N nodes have been assigned, the new K centroids are computed by taking the average of the datapoints in each cluster
  4. Go to step 2 and repeat until the datapoints stop changing clusters
Given below is a simulation of K-Means. Scroll below to find the buttons and instructions for interacting with this tool


  • Click figure or push [Step] button to go to next step.
  • Push [Restart] button to go back to initialization step.
  • Push [New] button to start new simulation with given N (the number of nodes) and K (the number of clusters).

Created using D3.js and ActionScript 3