Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← Machine Learning for Finance & Accounting Level Two · Lesson 7 of 9

Module Six

📖 Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
7
Module 6: Clustering & Segmentation in Finance for Young Coders
⭐ Module 6 · Level Two

Clustering &
Segmentation in Finance

🔵 Grouping things by similarity — without labels

🎯 What you'll learn in this module

  • ✔ How K‑means and hierarchical clustering work
  • ✔ How to segment customers and transactions
  • ✔ How to choose the right number of clusters
  • ✔ How clustering helps detect anomalies
  • ✔ How DBSCAN finds outliers in ledgers
  • ✔ How to interpret clusters in business terms
🧩
What Is Clustering?
The Big Idea

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.

🎨 Classification is "sort these into the labeled bins." Clustering is "here's a pile — create the bins yourself based on what's inside."
🔵
K‑Means: The Circle Maker
Model

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.

Cluster A · Low risk

🟢🟢🟢
Steady payers

Cluster B · Mid risk

🟡🟡🟡
Occasional delays

Cluster C · High risk

🔴🔴🔴
Frequent defaults
⭕ Like drawing circles around groups of friends at a party — each circle becomes a cluster.
🌳
Hierarchical Clustering: A Family Tree
Model

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.

👨‍👩‍👧 A family tree of clusters: siblings join into a family, families join into a neighborhood, neighborhoods join into a city. Cut at any level to see the grouping you need.
🎯
Choosing the Right Number of Clusters
Decision

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.

📊 Choosing K is like choosing how many drawers to organize your socks by colour. Too few = messy mix. Too many = wasted drawers. Just right = easy to find anything.
👥
Segmenting Customers & Transactions
Application

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.

🏪 A café has regulars, tourists, students, and office workers — same menu, different segment. Clustering reveals who's who without asking.
🔍
DBSCAN: Finding Outliers in Ledgers
Anomaly Detection

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).

🌲 A forest: dense groves become clusters. A single tree in a field is an "outlier." DBSCAN finds both, without being told what "normal" looks like.
💼
Interpreting Clusters in Business Terms
Insight

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.

🏷️ Clusters are labels. But a label isn't useful until you know what to do with the box.
📊 Raw data
→
🔵 Cluster
→
🎯 Choose K
→
💼 Interpret
→
🚀 Action
⚠️ Clustering is exploratory: There's no "right answer" like in supervised learning. K‑means with K=3 and K=5 may both be valid — they reveal different insights. Always try multiple K values, visualize the results, and ask: does this segmentation help make a business decision? If not, try again.

🛠️ Hands-on activities (no boring stuff!)

1

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?

2

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?

3

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?

4

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.

5

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?

6

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.

🏆 Get Certified

🔒

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

🎓 Sign Up to Get Certified
🛠️ Practice Tools
Hands-on simulators & labs - subscription required.
→
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
→