liveBook · Manning

Centroid

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

A centroid is a representative center of a cluster, typically computed as the mean position of its member points.

A centroid is the representative center of a cluster: the mean position of its assigned data points. In k-means, each point joins its nearest centroid, then every centroid moves to the mean of its cluster. section 6.2

Use centroids through this repeated k-means cycle:

  • Normalize dimensions when their magnitudes are not comparable; z-scores provide one normalization method. section 6.2
  • Initialize one centroid for each requested cluster, assign every point to its nearest centroid, and recompute each center coordinate by coordinate using the mean. section 6.2
  • Treat random initialization, the choice of k, outliers, and high-dimensional data as practical limitations; k-means++ and user-selected starting regions offer alternatives. section 6.4

Clustering governors

Represent each governor with longitude and age, normalize the dimensions, and run k-means with k = 2. One resulting cluster grouped several western states with relatively old governors, but randomized centroids can produce different results, so repeated runs and human interpretation are necessary. section 6.3

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Explains centroid assignment, coordinate-wise mean updates, convergence, initialization, and practical limitations.
Examples
Demonstrates centroids with Swift Point3D data and governor longitude-age clusters.
What you can do after
Build it from scratch with a Swift KMeans type that initializes, updates, and tests centroid convergence.
How it connects
Connects centroids to k-means clustering, normalization, z-scores, outliers, k-means++, k-medians, and k-medoids.

Also explained in

Compare how 7 books explain centroid →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.