liveBook · Manning

Centroid-based algorithm

As explained in Data Without Labels

Centroid-based clustering is a clustering approach that represents each group by a central point and assigns observations according to proximity to those centers.

Centroid-based clustering groups observations by their distance from cluster centers, called centroids. A smaller distance indicates greater similarity to a cluster. The choice of attributes matters: different attributes can produce different groupings of the same data. section 2.3 section 2.2

Figure 2.4 Centroid-based clustering methods create a centroid for the respective clusters, and the similarity is measured based on the distance from the centroid. In this case, we have five centroids; hence, we have five distinct clusters.
figure

The diagram shows five centroids and five corresponding clusters, making the point-to-center comparison visible. section 2.3

Distance gives the comparison a concrete meaning. Euclidean distance follows the straight line between points; Manhattan distance follows axis-aligned paths; Chebyshev distance takes the largest difference along any coordinate. Because distance defines similarity, the metric chosen affects how observations compare. section 2.3 section 2.2

K-means is a practical centroid-based starting point. Specify the number of clusters, k, and it iteratively assigns points to the nearest center to form nonoverlapping clusters. Its straightforward logic makes it useful as a benchmark before trying other clustering algorithms. section 2.10 section 2.3.5

Cluster vehicle measurements in Python

Load the vehicle CSV with pandas, inspect its shape, columns, class counts, and missing values, then drop the class column and standardize the measurements. Plot the data and compare k values using an elbow plot of average distortion. With k=3, fit scikit-learn’s KMeans, inspect cluster centers and label counts, and plot labeled observations using length, height, and weight. Repeat with different initializations and k values rather than relying on one run. section 2.3.5

Use the resulting labels and plots to judge whether the groups are useful for the problem at hand. If they are not, revisit the attributes, k, and algorithm: density-based and connectivity-based methods define groups differently. section 2.2 section 2.3.5

How Data Without Labels covers it

How deep it goes
Defines centroid proximity and distance metrics, then walks through data checks, standardization, k selection, fitting, and inspection without deriving k-means internals.
Examples
Uses a five-centroid diagram and a vehicle dataset with distortion plots, cluster centers, label counts, and a three-dimensional cluster plot.
What it assumes
Assumes basic Python data handling while defining centroids and explaining distance measures in accessible terms.
What you can do after
Apply it via scikit-learn’s KMeans to prepare vehicle measurements, choose k with an elbow plot, and inspect clusters as a benchmark.
How it connects
Links to k-means, distance metrics, the elbow method, and density-based and hierarchical clustering.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Without Labels. The section links point to the parts of the book it draws on.