K-means Clustering: Sorting Stocks Into Groups
Learn how K-means sorts stocks into a fixed number of look-alike groups, why you choose K, and why the group numbers don't mean anything.
Category: Machine Learning
In plain English
Imagine emptying a box of mixed buttons onto a table and sorting them into a set number of piles, where each button goes into the single pile it looks most like. K-means clustering does the same with stocks: it sorts them into a fixed number of groups so the stocks inside each group resemble one another. The 'K' is just the number of piles you decide to make before you start. Every stock lands in exactly one group, never two.
What it measures
K-means measures how alike stocks are based on their numbers, then puts each stock in the group whose 'centre' (the average of everything in it) is closest. It is a 'hard' grouping: one stock, one group, no partial membership. The computer keeps reshuffling stocks and recalculating each centre until the piles stop changing. - You first choose K, for example K=2 (two groups). - Each group has a centre = the average profile of its members. - A stock joins the group whose centre is nearest to it. - Tiny example: with the numbers 2, 3, 30, 31 and K=2, it splits into a {2, 3} group and a {30, 31} group.
How SurgeFlow uses it
SurgeFlow runs K-means as one of three grouping methods that feed the ML 'market map' tab. Instead of trusting any single method, it runs several and keeps the groupings they agree on, which is called a consensus. This is purely descriptive: it shows which stocks currently behave alike. It does not predict prices and is never a buy or sell signal.
How to read it on the site
Open the ML tab (the 'market map') and you will see stocks sorted into a handful of clusters. Think of each cluster as a family of stocks that look similar today, not a ranking from best to worst. A cluster labelled '3' is not better or worse than one labelled '1' the number is just a name, like a table number at a wedding. - Each stock sits in exactly one cluster. - Stocks in the same cluster share a similar profile right now. - The cluster numbers are labels, not scores or rankings.
What it cannot tell you
K-means describes structure; it does not forecast returns or tell you what to buy. The cluster numbers and IDs have no permanent meaning they can change between runs, so 'cluster 3' today may not be 'cluster 3' tomorrow. You must choose K yourself, and a different K gives different groups, so there is no single 'correct' picture. Finally, K-means assumes groups are roughly round and similar in size, so it can split or mislabel clusters that are stretched out, overlapping, or very uneven. - Cluster numbers are not stable across runs. - K is a human choice, not a fact different K, different groups. - Assumes round, similar-size groups; struggles with odd shapes. - Descriptive only: it is not advice and does not predict prices.