🔙 Back to Home

K-Means in Banking: Useful for Profiles, Not Labels

K-means can divide customers into groups with similar features, but it does not discover objectively correct customer segments. In my banking work, its value has been narrower and more useful: it turns a large customer table into a small number of profiles that analysts and business teams can inspect.

The business question comes before the clusters

The use case starts with customers who have already purchased insurance. The question is not “Who will buy insurance?”—that would require a labeled, supervised-learning problem. The question is “What different customer profiles exist inside the insurance portfolio?”

K-means can reveal a profile such as customers over 35 with high assets under management and frequent medicine or medical-examination transactions. This can support portfolio analysis and a more concrete discussion with the business, but the algorithm does not explain why those customers bought insurance or prove that the profile will remain stable.

There is no known target label in this task. A cluster number such as 2 has no business meaning until we inspect the customers and features assigned to it.

One row must represent one customer over one fixed window

Before choosing K, the analysis needs a customer-level feature table. Each row represents one customer, and every behavioral feature must be calculated over the same observation window. Relevant features for this use case include:

The observation window matters. A count over one month is not comparable with a count over twelve months, and mixing windows can create clusters that reflect feature construction rather than customer behavior.

Feature definitions also need to remain interpretable. If the business cannot explain what a high or low value means, it will be difficult to explain the resulting centroid.

Scaling decides what “similar customer” means

K-means usually relies on Euclidean distance. Without scaling, a monetary feature such as assets under management can dominate age or transaction frequency simply because it has a larger numeric range.

For this use case, the preparation step should therefore:

  1. Treat missing values consistently rather than allowing absence to become an accidental segment.
  2. Inspect highly skewed monetary and count features and apply a transformation when justified.
  3. Scale the final numeric features before calculating distances.
  4. Keep the transformation parameters so cluster profiles can later be translated back into business units.

This is not cosmetic preprocessing. Changing the scale changes the nearest centroid and can change the segment assigned to a customer.

K-means alternates assignment and centroid updates

Given N data points, K-means assigns them to K clusters according to their distance from the cluster centroids:

  1. Choose K, the number of clusters.
  2. Initialize K centroids, often from selected data points.
  3. Assign every point to its nearest centroid.
  4. Recalculate each centroid from the points assigned to that cluster.
  5. Repeat assignment and update until the assignments or centroids stop changing enough.

Because the initial centroids affect the final result, different initializations can produce different clusters. Running several initializations reduces the chance of reporting a poor local solution from one unlucky starting point.

Inertia cannot choose K by itself

The elbow curve uses within-cluster distance, commonly called inertia: the sum of squared distances from each point to its assigned centroid.

Elbow curve

Increasing K gives the algorithm more centroids, so inertia cannot increase. The smallest inertia therefore does not identify the best K; choosing one cluster per customer would minimize it without producing a useful segmentation. The elbow is the point after which additional clusters reduce inertia only slightly, but the bend is not always unambiguous.

Silhouette checks separation as well as compactness

For point i, the silhouette value is:

s(i) = (b(i) - a(i)) / max(b(i), a(i))

The silhouette score is the average of s(i) across all points. A higher value means points are closer to their own cluster than to neighboring clusters.

Silhouette score

Unlike inertia, silhouette does not move in one guaranteed direction as K increases. It helps compare candidate values of K, but its highest value is not automatically the best business choice. A solution with slightly lower silhouette may be preferable if its profiles are stable, sufficiently large, and meaningfully different.

A useful cluster needs a profile, not just an ID

For each candidate value of K, I use the elbow and silhouette together, then build a profiling table. At minimum, that table should contain:

Profile field Question it answers
Customer count and share Is the cluster large enough to matter?
Median age and assets under management What does a typical customer in the cluster look like?
Medicine and medical-examination transaction frequency Which behavior separates this cluster from the others?
Difference from the full portfolio Is the profile distinctive or merely average?

Centroids are calculated in the transformed feature space. For interpretation, the values should be converted back to understandable units where possible. The final names should describe the profile—such as “higher assets, frequent healthcare transactions”—rather than expose arbitrary labels such as “Cluster 2.”

Stability matters more than one attractive chart

A segmentation is difficult to use if its profiles change whenever the random seed or observation period changes. I therefore treat stability as a separate check:

If a small change in the data produces entirely different profiles, the segmentation is describing a fragile partition rather than a repeatable customer pattern.

Where K-means can give the wrong picture

K-means works best when Euclidean distance is meaningful and clusters are reasonably compact. It becomes less reliable when:

These limits explain why elbow and silhouette scores are necessary but insufficient. The final result still needs feature-level inspection and a business interpretation.

The output of this analysis is a set of descriptive profiles, not a prediction of who will buy insurance. If the goal changes to predicting purchase propensity, the cluster profile may become an exploratory feature, but it does not replace a supervised model and an out-of-sample evaluation.

🔙 Quay lại trang chủ

K-means trong ngân hàng: hữu ích cho chân dung, không phải nhãn

K-means có thể chia khách hàng thành các nhóm có feature tương tự, nhưng không khám phá ra những customer segment đúng một cách khách quan. Trong công việc ngân hàng của tôi, giá trị của nó hẹp hơn nhưng hữu ích hơn: biến một bảng khách hàng lớn thành một số ít profile để analyst và business cùng kiểm tra.

Câu hỏi business phải có trước các cluster

Use case bắt đầu với những khách hàng đã mua bảo hiểm. Câu hỏi không phải “Ai sẽ mua bảo hiểm?”—đó là một bài toán supervised learning có nhãn. Câu hỏi ở đây là “Trong portfolio bảo hiểm đang tồn tại những customer profile nào?”

K-means có thể cho thấy một profile gồm khách hàng trên 35 tuổi, có assets under management cao và thường xuyên phát sinh giao dịch mua thuốc hoặc khám bệnh. Kết quả này hỗ trợ phân tích portfolio và giúp trao đổi với business cụ thể hơn, nhưng thuật toán không giải thích vì sao họ mua bảo hiểm hoặc chứng minh profile sẽ ổn định theo thời gian.

Bài toán không có target label đã biết. Một cluster number như 2 không mang ý nghĩa business cho đến khi kiểm tra khách hàng và feature thuộc cluster đó.

Mỗi dòng phải là một khách hàng trong cùng observation window

Trước khi chọn K, phân tích cần một bảng feature cấp khách hàng. Mỗi dòng đại diện cho một khách hàng và mọi behavioral feature phải được tính trên cùng observation window. Các feature phù hợp với use case này gồm:

Observation window rất quan trọng. Số giao dịch trong một tháng không thể so trực tiếp với số giao dịch trong mười hai tháng; trộn các cửa sổ thời gian có thể tạo ra cluster phản ánh cách xây feature thay vì hành vi khách hàng.

Định nghĩa feature cũng phải dễ diễn giải. Nếu business không giải thích được giá trị cao hoặc thấp có nghĩa gì, centroid thu được cũng khó diễn giải.

Scaling quyết định thế nào là “khách hàng tương tự”

K-means thường dựa trên Euclidean distance. Nếu không scaling, một feature tiền tệ như assets under management có thể lấn át tuổi hoặc tần suất giao dịch chỉ vì có numeric range lớn hơn.

Với use case này, bước chuẩn bị dữ liệu cần:

  1. Xử lý missing value nhất quán, tránh để sự thiếu dữ liệu vô tình trở thành một segment.
  2. Kiểm tra các monetary feature và count feature bị lệch mạnh, rồi transform khi có căn cứ.
  3. Scale các numeric feature cuối cùng trước khi tính khoảng cách.
  4. Lưu transformation parameter để sau đó có thể chuyển cluster profile về đơn vị business.

Đây không phải preprocessing mang tính hình thức. Thay đổi scale sẽ thay đổi centroid gần nhất và có thể thay đổi segment được gán cho khách hàng.

K-means luân phiên assignment và cập nhật centroid

Với N data point, K-means gán chúng vào K cluster theo khoảng cách tới cluster centroid:

  1. Chọn K, số cluster.
  2. Khởi tạo K centroid, thường từ các data point được chọn.
  3. Gán mỗi point vào centroid gần nhất.
  4. Tính lại từng centroid từ các point thuộc cluster đó.
  5. Lặp lại assignment và update cho đến khi assignment hoặc centroid gần như không đổi.

Vì centroid ban đầu ảnh hưởng đến kết quả cuối, các initialization khác nhau có thể tạo ra cluster khác nhau. Chạy nhiều initialization giúp giảm khả năng báo cáo một local solution kém chỉ vì điểm khởi tạo không may.

Inertia không thể tự chọn K

Elbow curve sử dụng within-cluster distance, thường gọi là inertia: tổng squared distance từ từng point đến centroid được gán.

Elbow curve

Khi tăng K, thuật toán có thêm centroid nên inertia không thể tăng. Vì thế, inertia nhỏ nhất không xác định được K tốt nhất; nếu mỗi khách hàng là một cluster thì inertia sẽ nhỏ nhất nhưng segmentation không có ích. Elbow là điểm mà thêm cluster mới chỉ làm inertia giảm một lượng nhỏ, nhưng điểm gấp này không phải lúc nào cũng rõ ràng.

Silhouette kiểm tra cả độ tách biệt và độ chặt

Với point i:

s(i) = (b(i) - a(i)) / max(b(i), a(i))

Silhouette score là trung bình của s(i) trên toàn bộ point. Giá trị cao hơn nghĩa là point gần cluster của nó hơn các cluster lân cận.

Silhouette score

Khác với inertia, silhouette không có một chiều biến động cố định khi K tăng. Nó giúp so sánh các giá trị K, nhưng giá trị silhouette cao nhất không tự động là lựa chọn business tốt nhất. Một phương án có silhouette thấp hơn một chút vẫn có thể phù hợp hơn nếu profile ổn định, đủ lớn và khác biệt có ý nghĩa.

Một cluster hữu ích cần profile, không chỉ cần ID

Với mỗi giá trị K, tôi kết hợp elbow và silhouette rồi tạo profiling table. Tối thiểu, bảng này cần có:

Trường profile Câu hỏi cần trả lời
Số lượng và tỷ trọng khách hàng Cluster có đủ lớn để quan tâm không?
Median tuổi và assets under management Khách hàng điển hình trong cluster có đặc điểm gì?
Tần suất giao dịch mua thuốc và khám bệnh Hành vi nào phân biệt cluster này với cluster khác?
Chênh lệch so với toàn portfolio Profile có thực sự nổi bật hay chỉ ở mức trung bình?

Centroid được tính trong transformed feature space. Khi diễn giải, cần chuyển các giá trị về đơn vị dễ hiểu nếu có thể. Tên cuối cùng nên mô tả profile—chẳng hạn “tài sản cao hơn, giao dịch y tế thường xuyên”—thay vì để nhãn tùy ý như “Cluster 2”.

Stability quan trọng hơn một biểu đồ đẹp

Segmentation khó sử dụng nếu profile thay đổi mỗi khi đổi random seed hoặc observation period. Vì vậy, tôi coi stability là một bước kiểm tra riêng:

Nếu chỉ một thay đổi nhỏ trong dữ liệu đã tạo ra profile hoàn toàn khác, segmentation đang mô tả một partition mong manh chứ chưa phải customer pattern có thể lặp lại.

Khi K-means có thể tạo ra hình ảnh sai

K-means hoạt động tốt nhất khi Euclidean distance có ý nghĩa và các cluster tương đối compact. Kết quả kém tin cậy hơn khi:

Những giới hạn này cho thấy elbow và silhouette là cần thiết nhưng chưa đủ. Kết quả cuối vẫn cần kiểm tra ở cấp feature và diễn giải theo business.

Output của phân tích này là các descriptive profile, không phải dự báo ai sẽ mua bảo hiểm. Nếu mục tiêu chuyển thành purchase propensity, cluster profile có thể trở thành một exploratory feature, nhưng không thay thế supervised model và out-of-sample evaluation.