Sub topic 2
Finding segments in data with clustering
This chapter assumes you know the 4Ps, can read averages from a simple table, and have Python with numpy and scikit-learn installed. Clustering is a method that groups rows so that rows in the same group resemble each other. The method used here, k-means, needs you to choose the number of groups, k, in advance.
Finding segments in data with clustering
Standardize numeric columns before clustering. Otherwise, a column measured in dollars can outweigh a column measured in years.
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))Profiling segments
Profiling describes each group in plain terms so that you can name it and reach it. The column averages printed above are the first profile. Add the channels each group uses, such as email, social media or in-store visits.
| Segment | Average traits | Reach through |
|---|---|---|
| Cluster 0 | Younger, low spend | Social media |
Evaluating segments
Rate each segment from 1 to 5 on size, growth, profitability and fit with your company. A weighted sum turns those ratings into one score that you can rank.
segments = {
"Urban commuters": {"size": 4, "growth": 5, "profitability": 3, "fit": 5},
"Weekend riders": {"size": 3, "growth": 3, "profitability": 4, "fit": 2},
}
weights = {"size": 0.3, "growth": 0.2, "profitability": 0.3, "fit": 0.2}
scores = {
name: sum(weights[c] * r for c, r in ratings.items())
for name, ratings in segments.items()
}
for name, score in sorted(scores.items(), key=lambda item: item[1], reverse=True):
print(f"{name}: {score:.2f}")Targeting strategies
- Undifferentiated: one offer for the whole market.
- Differentiated: a separate offer for each of several segments.
- Concentrated: one segment only, often suited to a small firm with limited resources.
- Micromarketing: tailoring to individuals or local areas.
Selecting the target market
Choose the highest-scoring segment that passes the usability tests, then pick the targeting strategy that fits your resources.
Exercise
Why standardize the columns before running k-means?
Show answer
Standardizing stops columns with large values, such as spend in dollars, from dominating the distance calculation, so age and purchase frequency count equally.