AI Grounds

Open AI Grounds on a desktop

These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.

Guided discovery

K-Means Clustering Studio

Assign members. Then move their centroids.

Your dataset

Six authored points and two centroids, or group centers, share X/Y axes 0–100. Choose an object and edit its coordinates. Assign points chooses nearest centers by squared Euclidean distance, (X−center X)²+(Y−center Y)². Exact computed ties go to C1. Update centroids moves only the centers to their held members’ coordinate means.

00252550507575100100P1 (20,20), unassignedP1P2 (20,40), unassignedP2P3 (40,30), unassignedP3P4 (70,60), unassignedP4P5 (80,80), unassignedP5P6 (90,70), unassignedP6C1 center (10,20)C1C2 center (90,80)C2XY

Circles are data points; diamonds are centers. Indigo indicates held C1, orange C2 and gray unassigned. IDs, shapes and tables accompany color. Coincident marks can overlap. Labels use separate positions and leader lines; the exact tables retain every object. The selected object has a navy outline.

Edit P3's X value. Actual edits clear all assignments and restart at Ready. Means retain full precision; no coordinate grid is imposed. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Edit P3's Y value. Actual edits clear all assignments and restart at Ready. Means retain full precision; no coordinate grid is imposed. Use arrow keys on the slider. Press Enter or leave the number field to apply an exact edit.

Assign changes members without moving coordinates. Update changes centers without reassigning members. Assign again before the next Update. Empty centers keep their previous location.

Ready · Not assigned · 0 updates · C1=(10,20) · C2=(90,80)

Coordinate edits clear stale explanations and transfer answers. Object inspection, unchanged exact edits and an unchanged Assign preserve them. Changing scenario restores its coordinates and unassigned state. The display rounds to six decimals; operations use full precision. Clusters have no known class labels.

Cluster 1 members

Press Assign points first.

Unassigned

Current center: (10, 20)

Held from the last Assign points; Update does not reassign.

Cluster 2 members

Press Assign points first.

Unassigned

Current center: (90, 80)

Held from the last Assign points; Update does not reassign.

Assigned SSE

Sum of squared distances to each point's held assigned center.

Not assigned

Σ (X − center X)² + (Y − center Y)²

Squared coordinate units. Not class accuracy or a global-optimum certificate.

All six points

Distances and ties use current centers. Held assignment comes from the last Assign points and can differ from the current nearest center after Update.
IDXYd² to C1d² to C2Current tie?Held groupSSE term
P120201008500NoUnassignedNot assigned
P220405006500NoUnassignedNot assigned
P3403010005000NoUnassignedNot assigned
P470605200800NoUnassignedNot assigned
P580808500100NoUnassignedNot assigned
P690708900100NoUnassignedNot assigned

SSE is not defined until points have assignments.

Build the next centers

Each mean uses the currently held members. Update uses it only after Assign; a new assignment can change these means. Empty mean is undefined; this lab retains the current center.
CenterCurrent XCurrent YCountΣ XΣ YMean XMean YGroup SSE
C11020UnassignedNot assignedNot assignedNot assignedNot assignedNot assigned
C29080UnassignedNot assignedNot assignedNot assignedNot assignedNot assigned

C1: no assigned group yet.

C2: no assigned group yet.

Construction and limits

This is a hand-authored, six-point, two-center Lloyd demonstration. Coordinates are finite values within 0–100; fractional coordinate means are not rounded onto a grid or snapped to observed points. The display rounds to six decimals. Squared distances, means, ties and subsequent operations use JavaScript full-precision arithmetic. Exact equality of computed distances uses a fixed C1 tie rule.

For a fixed dataset, Assign picks a nearest center and Update minimizes each nonempty held group’s squared-distance sum by using its coordinate means. Either action cannot increase SSE apart from floating-point roundoff. Empty centers stay where they were; other algorithms/libraries can choose a different policy. Updating changes current distance ties without retroactively changing the last assignment. Another Assign may give an empty center members.

Initialization can change a local result; swapping center IDs merely renames equivalent groups. Stable assignments or centers do not guarantee a globally best clustering. No known classes, supervised accuracy, probability, learned embedding, choice of K, scaling study, automatic iterations or recommended seed strategy is supplied. Edits change the dataset/centers and restart assignment; monotonic SSE is not claimed across manual edits. Reset/prediction restores Separated seeds for the current experiment; free Reset restarts Experiment 1.

Stanford · K-Means assignment, mean update and local optima