Clustering is grouping similar things together — without being told what the groups are. Unlike classification, there are no labels to learn from. The model discovers natural groupings in the data by itself.
In finance, clustering helps you find customer segments, transaction groups, or unusual patterns you didn't know existed. It's like sorting a giant pile of unlabeled photos into piles by similarity.
K‑means is the most popular clustering algorithm. It works in three simple steps:
1. Pick K random cluster centers. 2. Assign each point to its nearest center. 3. Move each center to the average of its points. Repeat until stable.
The result: K clusters, each with a "center" (centroid). Choose K wisely — too few and you merge distinct groups, too many and you split real groups apart.
Hierarchical clustering builds a tree (dendrogram) showing how clusters merge at different levels of similarity. At the bottom, each point is its own cluster. At the top, everything is one cluster.
You can cut the tree at any level to get different numbers of clusters. This is powerful — it lets you explore multiple segmentations at once, rather than committing to a single K.
How many clusters should you use? There's no perfect answer — but two common tools help:
Elbow method: plot the total distance of points to their cluster centers for K = 1, 2, 3, … The plot often has an "elbow" — a point where adding more clusters doesn't help much. That's usually a good K.
Silhouette score: measures how well each point fits its own cluster vs. others. Scores close to 1 = clean separation, 0 = overlapping, negative = likely misassigned. Compare scores across K and pick the best.
Clustering is the backbone of customer segmentation in banking and retail finance. Typical segments:
| Segment | Behaviour | Business Action |
|---|---|---|
| High‑value loyal | Frequent, large purchases | Premium rewards, retention |
| Occasional | Rare purchases, price‑sensitive | Discount campaigns |
| Dormant | Haven't bought in months | Re‑engagement offers |
| Risky | Late payments, high debt | Careful credit, monitoring |
Same idea for transactions: clustering groups similar purchases together, which helps accountants categorize expenses and auditors spot anomalies.
DBSCAN is a density‑based clustering algorithm. Instead of "how close to the center," it asks "how many neighbors does this point have?"
Points in dense regions become clusters. Points in sparse regions become outliers — labeled "noise." That's gold for audit analytics: DBSCAN naturally separates "normal" transactions from suspicious ones without needing labels.
It also handles weird shapes that K‑means can't (like donut clusters or long strings of points).
Numbers mean nothing without interpretation. When you finish clustering, ask:
What's the shared trait? Are they high spenders, frequent users, or risky borrowers? Give each cluster a human name: "The Loyal Regulars," "The Bargain Hunters," "The Risk Watch."
What action follows? Each segment needs a business response — a marketing campaign, a credit limit, a follow‑up. Clusters are only useful when they drive decisions.
Sort by similarity: List 10 imaginary customers with (monthly spending, visit frequency). Group them into 3 clusters by eye. Give each cluster a name (e.g., "The Loyal Regulars"). Then ask: would a bank treat these groups differently?
K‑means by hand: Take 6 points on a number line (1, 2, 3, 8, 9, 10). Try K=2. Pick initial centers 2 and 8. Assign each point to its nearest center. Move centers to the average of their points. Repeat once. What clusters did you end up with?
Elbow intuition: Imagine plotting "within‑cluster distance" for K=1, 2, 3, 4, 5: 100, 60, 40, 38, 37. Where's the "elbow"? Which K would you choose, and why?
Segment design: For a bank, invent three customer clusters and describe each in one sentence. Then propose one business action per cluster — a loan offer, a savings account, or a fraud check.
Outlier hunt: In a list of 20 transaction amounts ($5, $8, $7, $6, $9, $5, $1,500, $6, $7, $8…), which one looks like an outlier? Would DBSCAN likely flag it? Why or why not?
Cluster labels: Given three clusters of students — Cluster A averages 95 in math, Cluster B averages 60, Cluster C averages 75 — write a short label for each. What if Cluster C's students all improved by 10 points this month? Would you relabel them?
By the end of this module, you'll be able to: run K‑means and hierarchical clustering, choose K with the elbow method and silhouette score, segment customers and transactions, use DBSCAN to detect outliers, and interpret clusters in clear business language.