Module 17 · Finding Hidden Groups

How do you pick the number of groups, and why did one column take over?

Lesson 17.3 · How Many Groups?

Felix · Rosa

Tempo: 60 to 200. Energy: 0 to 1. Guess which one the distance cares about.

Felix switches the map to tempo and energy and the clusters turn into vertical stripes.

Tempo runs from 60 to 200 and energy from 0 to 1, so tempo is the only thing the distance formula can see.

Then Rosa asks the question k-means can’t answer: why three groups? Why not five?

The short answer

Choosing k, and scaling: K-means needs to be told how many groups to find, and it will find that many whether or not they exist. It also measures distance in raw units, so a feature with big numbers dominates. Scaling every feature to the same range first is not optional. Choosing k is a judgment, backed by a few tools.

Try it yourself

Slide the number of groups and watch the map re-cluster. Then flip “same scale” on and see what tempo was hiding.

Slide the number of groups and watch the map re-cluster. Then flip “same scale” on and see what tempo was hiding.Unholy (feat. Kim Petras)Quevedo: Bzrp Music Sessions, Vol. 52I'm Good (Blue)La BachataMe Porto BonitoTití Me PreguntóUnder The InfluenceEfectoI Ain't WorriedOjitos LindosAs It WasMoscow MuleGlimpse of UsSweater WeatherAnother LoveCUFF ITNeveritaPROVENZALeft and Right (Feat. Jung Kook of BTS)Super Freaky GirlI Wanna Be YoursCalm Down (with Selena Gomez)Jimmy Cooks (feat. 21 Savage)LOKERATarotCaileBlinding LightsVegas (From the Original Motion Picture Soundtrack ELVIS)FerrariAtlantisSTAR WALKIN' (League of Legends Worlds Anthem)Te FelicitoPartyLa CorrienteRunning Up That Hill (A Deal With God)StarboyMIDDLE OF THE NIGHTDandelionsUntil I Found YouI Was Never ThereGATÚBELASex, Drugs, Etc.Something in the OrangeOne Kiss (with Dua Lipa)Gangsta's ParadiseSTAY (with Justin Bieber)BILLIE EILISH.About Damn TimeWAIT FOR U (feat. Drake & Tems)I Love You SoLA INOCENTEcómo dormiste?Hold Me Closerlovely (with Khalid)Call Out My NameWatermelon SugarSave Your TearsBonesWomanWhere Are You NowI'm Not The Only OneDo I Wanna Know?505Why'd You Only Call Me When You're High?Mary On A CrossWithout MeNo Role ModelzKesariya (From "Brahmastra")Heat WavesAfter LIKELA CANCIÓNBABY OTAKULa Llevo Al Cielo (Ft. Ñengo Flow)Night ChangesGhostBad Habitsdrivers licenseThe HillsDie For Youtraitorgood 4 uDon’t Blame MeHappier Than EverBelieverEvergreen (You Didn’t Deserve Me At All)Daddy IssuesMiss YouOnly Love Can Hurt Like ThisBad Decisions (with BTS & Snoop Dogg)NumbBelly DancerBam Bam (feat. Ed Sheeran)Locked out of HeavenRevengeTHATS WHAT I WANTThe Real Slim ShadyBetty (Get Money)Shut DownYonaguniLo Siento BB:/ (with Bad Bunny & Julieta Venegas)Un RatitoFeliz Cumpleaños FerxxoDos Mil 16Un CocoPerfectSomeone You LovedHeatherdeja vuEverybody Wants To Rule The WorldSoftcoreMr. BrightsideabcdefuYou ProofThe NightsThere's Nothing Holdin' Me BackThe Mottoeverything i wantedHopeINDUSTRY BABY (feat. Jack Harlow)Till I CollapseFirst ClassSupermanBeggin'FreaksTalk that TalkPepasProhibidoxAndreaShape of YouPeaches (feat. Daniel Caesar & Giveon)augustIn The StarshappierEnemy (with JID) - from the series Arcane League of LegendsEvery Breath You TakeCreepIn the EndEasy On MeLost in the Fire (feat. The Weeknd)Levitating (feat. DaBaby)positionsSomething Just Like ThisLeave Before You Love Me (with Jonas Brothers)Wake Me UpWords (feat. Zara Larsson)Bad Memories (feat. Elley Duhé & FAST BOY)Crazy What Love Can DoLet Me Down SlowlyBoredEverybody Dies In Their NightmaresHighway to HellBack In BlackOne DanceStanTHE LONELIESTShinunoga E-WaDynamitePink VenomYet To ComeLOVE DIVEMEMORIASPUNTO 40X ÚLTIMA VEZLos CachosOtro AtardecerNormalYo No Soy CelosoMe Fui de VacacionesLivin' On A PrayerSomewhere Only We KnowRunning Up That Hill (A Deal With God) - 2018 RemasterInfinityBlank SpaceHymn for the WeekendMemoriesPhotographSay You Won't Let GoLoverMAMIIIThunderHouse of MemoriesStressed OutTake on MeClean White Noise - Loopable with no fadeAll of MePink + WhiteLostSeven Nation ArmyLosing My ReligionEverlongFeel Good Inc.ApocalypseHotel California - 2013 RemasterHave You Ever Seen The RainRock and A Hard PlaceCloserLet Me Love You7 ringsLevitatingNeed to KnowTreat You BetterYou RightHips Don't Lie (feat. Wyclef Jean)Leave The Door OpenShallowDon't Be ShyHot In Itbad guyDeep Down (feat. Never Dull)Jocelyn FloresStill D.R.E.EnvolverBamba (feat. Aitch & BIA)Sweet Child O' MineThunderstruckGod's PlanHUMBLE.goosebumpsYKWIM?Pumped Up KicksRun BTSYo Voy (feat. Daddy Yankee)La SantaEnséñame a BailarAguaceroI'm Still StandingWhat Makes You BeautifulLove Yourselfyou broke me firstPayphoneHeartbreak AnniversaryDemonsLittle Dark AgeYou Get Me So HighSmells Like Teen SpiritShut Up and DanceNumbChop Suey!KICK BACKdouble takeWasted On YouNo LieI Like Me BetterAttentionStuck with U (with Justin Bieber)HappierToo Good At GoodbyesOne Last TimeMoth To A Flame (with The Weeknd)Bye ByeStreetsThat's What I LikeUptown Funk (feat. Bruno Mars)For My Hand (feat. Ed Sheeran)21 Reasons (feat. Ella Henderson)Last LastSeptemberWhere Did You Go? (feat. MNEK)Fuck Love (feat. Trippie Redd)SAD!MoonlightThe Night We MetR U Mine?Don't Stop Believin'Summer HighNo LoveMONTERO (Call Me By Your Name)Mask OffGodzilla (feat. Juice WRLD)All The Stars (with SZA)Love The Way You LieN95In Da ClubFair Trade (with Travis Scott)SICKO MODEFormulaMount EverestI WANNA BE YOUR SLAVEWashing Machine HeartLovers RockSUPERMODELNotionTek It - Sped UpYoungRush Hour (Feat. j-hope of BTS)ButterFEARLESSDÁKITIBesos Moja2DesesperadosSi Te La Encuentras Por AhíVolvíVolando - RemixParty en el Barrio (feat. Duki)DilesUN PESOSi Estuviésemos JuntosA Tu MercedAgostoEl ApagónAB

What you just did has a name

Choosing k, and scaling

K-means needs to be told how many groups to find, and it will find that many whether or not they exist.

It also measures distance in raw units, so a feature with big numbers dominates.

Scaling every feature to the same range first is not optional. Choosing k is a judgment, backed by a few tools.

A few more things

Scale first, always

Tempo in beats per minute swamps energy on a 0-to-1 scale by a factor of a hundred. Standardize both (subtract the mean, divide by the spread) and they get an equal vote. Module 5’s cleaning rule, one more time.

K is a knob, not a discovery

Ask for five groups and you get five, even in a perfectly even cloud. The groups are only as real as the gaps between them. Try several values and see which ones stay stable when the random start changes.

Diminishing returns

Going from one group to two tightens things a lot. Two to three, a bit. Six to seven, barely. Plot that tightness against k and look for the bend, the point where more groups stop buying much. That bend is a common way to pick.

Go deeper

The longer version, if you want it.

The elbow and the silhouette

The “bend” is called the elbow method: plot total within-cluster distance against k and pick the k where the curve flattens. It’s rough, and sometimes there’s no clear elbow. The silhouette score is more formal: for each point, compare how close it is to its own cluster versus the next nearest cluster, averaged over all points. Higher is better, and the k with the highest silhouette is a defensible choice.

Neither replaces judgment. If the elbow says four and the four groups have no meaning a person can name, three meaningful groups are better. Module 17.4 is about the naming.

Quick check

You cluster players by height in centimeters and by free-throw rate as a decimal from 0 to 1. Before running k-means, what has to happen?

Let’s take it slower

K-means has two knobs you set yourself, and it won’t set either one for you. The first knob is k, and the machine always produces exactly that many groups, even from a cloud with no groups in it, so you try a few values and keep the ones that hold up. The second knob is scale. Distance is measured in whatever units you hand over, so a column counted in hundreds shouts and a column between 0 and 1 whispers. Put every column on the same footing first, then turn the k knob on purpose.

More examples

1

Grouping houses for sale

Cluster listings by price in dollars and number of bedrooms and you get groups sorted purely by price, because 350,000 swamps 3. Scale both to the same range and the bedroom count finally gets a say. Same data, honest groups.

2

How many friend groups

Ask a clustering tool for eight friend groups in a class of 25 and it hands you eight, some with two people who barely know each other. Ask for two and it splits along whatever line is biggest. The number of groups is your call, and a bad call still gets an answer.

Back to the question

So how many vibes?

Show the answer

With scaling on, three groups stay stable and four splits one of them into two nearly identical halves. Three it is. And the vertical stripes were never vibes. They were tempo shouting over everything else, until Felix put it on the same scale as energy.

One last question

Felix explains k-means settings to Ashley. Trust him?

“K-means figures out how many groups there are on its own.”

“If one feature has much bigger numbers, it dominates the distance unless you scale.”

“Pick the k where adding another group stops tightening things much.”

Talk Card

Talk Card · 17.3

Clustering won’t tell you how many groups there are, and it can’t compare tempo to energy until both are on the same scale. Scale first, then choose k on purpose.

Data to AI · pettigrewlab.com/learn

Next lesson