liveBook · Manning

Elbow method

As explained in Data Without Labels

The elbow method is a heuristic for selecting a model complexity value by locating a sharp bend in a curve of objective performance versus that value.

K-means needs a number of clusters, k, before it can run. The elbow method helps choose a candidate: fit the model at several k values, plot a within-cluster measure against k, and look for a sharp bend. That bend suggests a useful cluster count, not an automatic final answer. section 2.3.3

A practical selection workflow:

  • Inspect the data and standardize the features before comparing clusters. Features on different scales can otherwise dominate distance calculations. section 2.3.5
  • Fit K-means across candidate k values and plot the resulting scores. The conceptual illustration uses within-cluster sum of squares (WCSS); the supplied Python example instead plots average Euclidean distortion, so its values should not be labeled WCSS. section 2.3.3 section 2.3.5
  • Inspect the bend, then check cluster sizes, computation cost, and whether business logic calls for merging or splitting clusters. The silhouette coefficient offers another way to assess the choice. section 2.3.3

Vehicle clustering

A Python workflow standardizes vehicle features, compares candidate values of k, and identifies a sharp bend at k = 3. It then fits a three-cluster K-means model and examines the resulting centroids and labels. Three suits this dataset; it is not a universal setting. section 2.3.5

from sklearn.cluster import KMeans
from scipy.spatial.distance import cdist
clusters=range(1,10)
meanDistortions=[]
for k in clusters:
    model=KMeans(n_clusters=k)
    model.fit(X_standard)
    prediction=model.predict(X_standard)
    meanDistortions.append(sum(np.min(cdist(X_standard, 
        model.cluster_centers_, 'euclidean'), axis=1)) / X_standard
                                                          .shape[0])
plt.plot(clusters, meanDistortions, 'bx-')
plt.xlabel('k')
plt.ylabel('Average distortion')
plt.title('Selecting k with the Elbow Method')

The Python listing fits KMeans repeatedly and plots average distortion against k; inspect the plotted measure before interpreting its elbow. section 2.3.5

Hierarchical clustering handles this decision differently: it does not require k as an algorithm input, but a cut through its dendrogram still determines how many final clusters to retain. section 2.4.3

How Data Without Labels covers it

How deep it goes
Walks through a plotted selection and Python fitting loop, but leaves the final count subject to business judgment.
Examples
Uses standardized vehicle features and an average-distortion plot whose sharp bend suggests three clusters.
What it assumes
Assumes a numeric feature set ready for clustering and explains how to choose k from a plotted comparison.
What you can do after
Apply it via scikit-learn KMeans to compare candidate cluster counts, then assess the choice against cluster sizes and business needs.
How it connects
Connects K-means and WCSS with feature standardization, the silhouette coefficient, and dendrogram-based cluster selection.

Also explained in

Compare how 5 books explain elbow method →

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.