k-Means

Edit a point cloud and follow k-means++ assignment and centroid updates step by step.

About this tool

Build a point cloud by clicking, load a seeded demo or paste coordinate pairs. k-Means groups nearby points around k centers. Run alternates assignment and update; Step performs just one of those phases. Pause/Continue keeps the current centers. Reset keeps the points but clears clustering. Changes to k or the seed reset the model.

Initialization uses seeded k-means++. Assignment chooses the nearest center by squared Euclidean distance; a tie chooses the first center. Update moves each center to the arithmetic mean of its assigned points; an empty group retains its previous center. One full iteration consists of both phases. Stop when assignments are unchanged after an update, or after 200 full iterations. This finds a local solution; try other seeds. SSE is the sum of squared distances to the currently assigned centers; each phase should not increase it.

Group colors and numbered center markers match the numeric table. Reassigned counts the latest assignment changes; the first assignment counts all points. A fixed 700 × 460 coordinate frame has X rightward, Y downward and equally scaled axes. Paste exactly two finite numbers per line, separated by spaces, comma or semicolon, using decimal points. Blank lines and # comments are ignored; other invalid lines reject the import while keeping the previous points. Limits: X 0–700, Y 0–460, 2,000 points, 1 MiB. Demo blobs are clipped to this editable frame.

Points to text preserves numeric coordinates; CSV exports current point assignments as 1-based group numbers, including intermediate phases. Example: (100,100), (100,120), (300,100), (300,120), k=2 gives centers (100,110)/(300,110) and SSE=400. This is an editable learning surface, with no automatic choice of k, feature standardization or global-optimum guarantee. For other clustering methods and CSV-column selection use Clustering Lab.

Only input values are remembered in this browser. Calculated results and experiment histories are not saved.