← Back to the collection
LEARNING / 2021 / LEARNING STUDY

Before the lab, eight points.

Eight Points, Three Clusters

The original K-means exercise: assign eight points, move three centroids, print the iterations, repeat.

MEDIUM
  • Python
BUILT WITH
  • NumPy
  • Object-oriented modelling
ACCESS

Public source

01

A small enough world to inspect

Separate Point and Cluster classes hold membership and representative positions. Each iteration finds the nearest centroid, moves observations between clusters, updates the means, and compares centroid movement.

02

An idea worth returning to

The original README proposed plotting points and animating the changing clusters. In 2026, Clustering 3D Lab takes that direction further—and preserves the original eight-point dataset as a link back to this implementation.

SYSTEM SKETCH / CONCEPTUAL OVERVIEW
8 POINTS → 3 INITIAL CENTROIDS
    │              │
    └─ nearest ────┘
          │
     update means
          │
    repeat until settled
A reading of the architecture, not an application screenshot.
SYSTEM MAP / CLASS RELATIONSHIPS / ITERATION

Membership belongs to points; the mean belongs to a cluster.

kMeans → Point: generate points. kMeans → Cluster: generate clusters. Point → find_closest_centroid: coordinates. Cluster → find_closest_centroid: centroids. find_closest_centroid → update_centroid: new memberships. update_centroid → is_converged: movement. is_converged → find_closest_centroid: continue if moving.123456701 / CONTROLLERkMeansEight input coordinatesThree initial representatives02 / CLASSPointid · x · y · cluster_numberset_cluster_number()03 / CLASSClustercluster_points · centroidcalculate_distance()04 / ASSIGNMENTfind_closest_centroidargmin of distancesRemove / add membership05 / UPDATEupdate_centroidMean of member coordinatesCompare old / new centres06 / TERMINATIONis_convergedSum of movement == 0Or iteration bound reached
  1. 01 / controller

    kMeans

    Eight input coordinates

    Three initial representatives

    • generate points → 2. Point
    • generate clusters → 3. Cluster
  2. 02 / class

    Point

    id · x · y · cluster_number

    set_cluster_number()

    • coordinates → 4. find_closest_centroid
  3. 03 / class

    Cluster

    cluster_points · centroid

    calculate_distance()

    • centroids → 4. find_closest_centroid
  4. 04 / assignment

    find_closest_centroid

    argmin of distances

    Remove / add membership

    • new memberships → 5. update_centroid
  5. 05 / update

    update_centroid

    Mean of member coordinates

    Compare old / new centres

    • movement → 6. is_converged
  6. 06 / termination

    is_converged

    Sum of movement == 0

    Or iteration bound reached

    • continue if moving → 4. find_closest_centroid
  1. 1kMeans Pointgenerate points
  2. 2kMeans Clustergenerate clusters
  3. 3Point find_closest_centroidcoordinates
  4. 4Cluster find_closest_centroidcentroids
  5. 5find_closest_centroid update_centroidnew memberships
  6. 6update_centroid is_convergedmovement
  7. 7is_converged find_closest_centroidcontinue if moving
The source prints each iteration and stops before iteration ten if centres have not settled. The portfolio’s interactive detour is a separate browser reconstruction.
Read from the implementation
  • kmeans.py
  • point.py
  • cluster.py
CONTINUE EXPLORING

Clustering 3D Lab →

Four clustering methods. One spatial laboratory. A way to see not just where an algorithm lands, but why it gets there.

2026
  • TypeScript