I wanted a project small enough to finish in a weekend but real enough to change how I think. RFM segmentation on a public retail dataset fit the brief: three features, clean intuition, and a chance to actually defend the number of clusters I picked.
Setup
Standard pipeline. Log-transform skewed features, standard scale, run K-Means for k in 2..10, look at inertia and silhouette. The elbow was polite but not obvious. Silhouette peaked at k=4, so I went with 4.
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
X = StandardScaler().fit_transform(np.log1p(rfm))
km = KMeans(n_clusters=4, n_init=20, random_state=42).fit(X)Where the score lied
Two of the four clusters were basically the same group split down the middle by a single recency threshold. The silhouette didn't care. A business person would have. I merged them by hand and the three-segment story was much easier to explain, which mattered more than the metric.
"The model is a suggestion. The segmentation is a decision."— something I'll keep repeating to myself
What I'd do next time
- Start with the business question, not the algorithm.
- Validate clusters with a domain proxy (revenue share, retention curve) before trusting silhouette.
- Write the segment personas before touching the deck.