16.1. Clustering Concepts#

This section introduces clustering as an unsupervised learning task for finding useful groups in data. Unlike the supervised learning of Classification, the data include no right answers (labels) to learn from; the method looks for structure on its own. A cluster is not automatically a market segment, a customer type, or a strategy. It is a pattern in the data that still needs interpretation.

16.1.1. Clustering as a Management Tool#

Clustering is useful when an organization has observations but no labels. A retailer may have customer purchase histories without predefined customer types. A human-resources team may have survey responses without known engagement groups. A product team may have usage logs without clear user personas.

The clustering workflow turns those unlabeled observations into candidate groups. When the groups divide customers, products, or cases for a business purpose, this is called segmentation. The analyst then asks whether the groups are stable, interpretable, and useful for a decision.

16.1.2. Similarity and Features#

Clustering depends on a definition of similarity. Most introductory clustering examples use numeric features and Euclidean distance, where points close together are treated as similar. A rule for measuring how far apart two observations are is called a distance metric, and Euclidean (straight-line) distance is the usual choice. That means feature choice matters as much as the algorithm. A noisy feature, one that varies a lot but says nothing about the groups you care about (a random ID number, say), distracts the algorithm and can blur real clusters, so leave such columns out.

For example, clustering customers by annual spending and number of purchases will emphasize purchasing behavior. Clustering the same customers by age and distance from a store will emphasize demographics and geography. Both can be reasonable, but they answer different questions.

16.1.3. Scale and Distance#

Scale can dominate a clustering result. If one feature is measured in dollars and another is measured as a count from 1 to 10, the dollar feature may control the distance calculation simply because its numbers are larger.

The fix is feature scaling: transforming features so their scales are comparable before clustering. The most common form is standardization, which subtracts each feature’s mean and divides by its standard deviation (the standard units of Correlation). Standardization does not make a clustering result correct by itself, but it prevents units from silently deciding the groups.

16.1.4. Common Clustering Methods#

Different clustering algorithms encode different ideas about what a group should look like.

  • K-means partitions observations into a fixed number of compact clusters.

  • Hierarchical clustering builds nested groups that can be viewed as a tree.

  • DBSCAN finds dense regions and can mark isolated points as noise.

This chapter focuses on k-means because it is simple, common, and useful for learning the core workflow.

16.1.5. Practical Interpretation#

A cluster label such as 0, 1, or 2 has no built-in meaning. The meaning comes from the observations inside the cluster: their averages, ranges, common traits, and relationship to the management question. Deciding whether a grouping is useful takes domain judgment, subject-matter reasoning about whether the groups make sense for the business. The algorithm cannot supply it.

Describing each cluster in business language, not only algorithm output, is cluster interpretation. It is what gives a result interpretability: how easily it can be explained. For example, “high-value repeat purchasers” is more useful than “cluster 2” if the group actually shows high spending and frequent purchases.

16.1.6. Section Practice#

Use this short exercise to check the main workflow from this section.

### Exercise: Practice Clustering Concepts
# Customers are described by annual spend (dollars) and store visits per month.
# Which customer is most similar to A depends on the scale of the features.
#   1. Compute the distance from A to B and from A to C on the raw features.
#   2. Divide each feature by its standard deviation (spend_sd, visits_sd) and
#      compute the same two distances again.
#   3. Print which customer is closer to A each time.
# Print exactly:
# Raw features: B is closer to A
# Scaled features: C is closer to A
import numpy as np

A = np.array([1000, 2])    # [annual spend, visits per month]
B = np.array([1050, 12])
C = np.array([1300, 3])
spend_sd = 400
visits_sd = 4
### Your code starts here.




### Your code ends here.

Hide code cell source

### Solution
import numpy as np

A = np.array([1000, 2])    # [annual spend, visits per month]
B = np.array([1050, 12])
C = np.array([1300, 3])
spend_sd = 400
visits_sd = 4

def distance(p, q):
    return np.sqrt(np.sum((p - q) ** 2))

def closer_to_A(dist_b, dist_c):
    return 'B' if dist_b < dist_c else 'C'

sd = np.array([spend_sd, visits_sd])
print('Raw features:', closer_to_A(distance(A, B), distance(A, C)), 'is closer to A')
print('Scaled features:', closer_to_A(distance(A / sd, B / sd), distance(A / sd, C / sd)), 'is closer to A')
# On the raw features, a $50 spend gap outweighs a gap of 10 visits a month.
Raw features: B is closer to A
Scaled features: C is closer to A