K-Means Clustering Calculator

Read the Theory Guide →

Enter numeric data points, choose K and the starting centroids, and run K-Means to see how distances, cluster assignments, and centroids change across iterations. Edit the data or starting points and rerun to see how the grouping changes.

What You Can Explore

  • Edit the table of numeric points by changing values and adding or removing rows, keeping at least two feature columns.
  • Set K between 2 and 10, then choose a data point as the starting centroid for each cluster.
  • Run the clustering and inspect each iteration's distances, cluster assignments, and newly calculated centroids.
  • Compare iterations to see which points switch clusters and when the assignments stop changing.
Core Mechanics
▼
  • Batch Assignment First: Compare every point to its nearest centroid before you do anything else. Do not move or update any centroids until every single point has been assigned to its closest match.
  • Recenter to the Mean: Only after the full assignment is complete, shift each centroid to the exact center (the average) of its newly assigned points. This is the only time the centroids move.
  • Strict Iterative Sequence: Always follow the cycle: Assign → Update → Check. Mixing up this sequence is the fastest way to lose points on a trace table.
  • Convergence (The Exit Rule): You are finished when the assignments in the current iteration perfectly match the assignments from the previous one. If even one point changes its cluster, run it again!
Initializing Workspace...

Understanding Your Result

The iterations are calculated from your points, chosen K, and starting centroids. Each iteration shows the distances used for assignment, the resulting cluster for every point, and the new centroid calculated from each cluster.

  • The Assigned Cluster column shows which current centroid is closest to each point. The starting centroids shown at the top of the iteration are the centroids used for those distance calculations.
  • After the assignments are made, each cluster's new centroid is calculated from the points assigned to it. The next iteration starts from those updated centroids.
  • Compare the cluster assignments between iterations to see whether points move between clusters. The run converges when the assignments stop changing.
  • If a cluster receives no points, the solver keeps its centroid unchanged for that iteration. Check the iteration where the empty cluster appears to see how the assignments led to it.

Try These Experiments

Change the Starting Centroids

Setup: Run the preloaded data with K = 2 and the default starts, C1 = P1 and C2 = P2. Note the final groups and the number of iterations.

Action: Change the starting centroids to C1 = P5 and C2 = P6, then run K-Means again.

What to Observe: The second run takes four iterations instead of two. P1, P4, and P5 switch clusters during the run, and the final groups match the first run with the C1 and C2 labels reversed.

Takeaway: Different starting centroids can change the path K-Means takes to reach a grouping and how many iterations it needs. The cluster labels themselves are arbitrary, so reversed C1 and C2 labels can still represent the same final groups.

Increase K to 3

Setup: Run the preloaded data with K = 2 and the default starts, where four points finish in C1 and two points finish in C2.

Action: Change K to 3, keep C1 = P1 and C2 = P2, leave the new C3 at P3, and run K-Means again.

What to Observe: P2 and P3 each remain in their own one-point cluster, while P1, P4, P5, and P6 stay together in the remaining cluster. Their centroids stop moving after the next assignment.

Takeaway: Changing K changes how many clusters the solver maintains. A larger K does not automatically produce more meaningful groups; inspect the resulting assignments and centroids to see whether the extra cluster is useful.

Add an Extreme Outlier

Setup: Run the preloaded data with K = 2 and the default starts, where P6 is (188, 77) and belongs to the larger cluster.

Action: Change P6 to Height 250 and Weight 150, leave the other points and starting centroids unchanged, and run K-Means again.

What to Observe: After Iteration 1, C1 moves to (199, 90.5) because it includes the extreme P6. In Iteration 2, P1, P4, and P5 move to C2, leaving P6 alone in C1.

Takeaway: Because a centroid is calculated from the average of its assigned points, an extreme point can pull the centroid far from the rest of the data and change later assignments. Use the iteration values to see that effect rather than judging the final clusters alone.