Sub topic 5
Finding Segments in Data with Clustering
Assume you know basic marketing vocabulary, can read averages, and understand the earlier STP steps. This chapter focuses on one way to discover customer groups from data. It does not replace market knowledge or customer research.
What clustering does
Clustering is a data analysis method that groups records that resemble one another. In marketing, each record might represent a customer, company, household, or purchase account. The columns describe attributes such as age, annual spend, purchase frequency, location, or product usage.
A clustering algorithm does not begin with labels such as “loyal customers” or “budget shoppers.” It identifies patterns in the input variables. You then study the resulting groups and give them useful names.
K-means is a common clustering algorithm. It works by:
- Choosing a number of groups, called
k. - Placing a center, or centroid, for each group.
- Assigning each record to its nearest centroid.
- Moving each centroid to the average of its assigned records.
- Repeating the assignments and movements until the groups stabilize.
The result is a cluster label for every record. A label such as 0 or 1 has no business meaning by itself.
Why standardization matters
Variables often use different scales. Annual spend might range from 100 to 10,000, while purchases per year might range from 1 to 20. If you calculate distance directly, spend can dominate the grouping simply because its numbers are larger.
Standardization puts each variable on a comparable scale. A standardized value describes how far a record is from that variable's average, measured in standard deviations.
import numpy as np
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
# Columns: age, annual spend, purchases per year
customers = np.array([
[22, 300, 4],
[25, 350, 5],
[41, 1500, 14],
[45, 1600, 16],
[63, 700, 6],
[67, 650, 5],
])
scaled = StandardScaler().fit_transform(customers)
model = KMeans(n_clusters=3, n_init=10, random_state=0)
labels = model.fit_predict(scaled)
for label in sorted(set(labels)):
members = customers[labels == label]
print(label, members.mean(axis=0))The printed averages help profile each cluster. You might find a younger, low-spend group; a middle-aged, high-frequency group; and an older, moderate-spend group. The exact numeric labels can change between analyses, so interpret the averages rather than the label numbers.
Common errors and safeguards
The choice of variables determines the groups. Including irrelevant variables can create meaningless clusters. Including two highly related variables can give one customer trait too much influence.
The choice of k also requires judgment. Test several values and compare measures such as within-cluster variation, stability across samples, and business usefulness. A mathematically neat solution is not automatically a useful market segment.
Clustering finds associations, not causes. A high-spend cluster does not prove why those customers spend more. Use surveys, interviews, experiments, and market context to explain the pattern.
From clusters to segments
A cluster becomes a practical segment only after interpretation. For each group, record:
- Its size and share of customers.
- Typical demographics, needs, behaviors, or firm characteristics.
- Purchase value and likely profitability.
- Channels where members can be reached.
- Evidence that the group differs from other groups.
- Possible products and messages for the group.
Clustering is therefore a discovery step. The marketer still evaluates, selects, and names the segments before moving to targeting.
Exercise
Why should annual spend and purchases per year be standardized before k-means clustering?
Show answer
They should be standardized because their numeric scales differ. Without standardization, the larger-scale variable can dominate distance calculations and distort the groups.