Skip navigation
➡️ Machine Learning from Scratch, part 17: k-means clustering in 16 lines of Python.
0:00 / 2:24

➡️ Machine Learning from Scratch, part 17: k-means clustering in 16 lines of Python.

148,700 views #machinelearning #ai #kmeans

➡️ Machine Learning from Scratch, part 17: k-means clustering in 16 lines of Python. Our photos are simulated. A small program of ours placed 600 photos from three made-up trips on a map: 250 in a city, 200 along a coast and 150 on a mountain trail. The program never sees which photo belongs to which trip. How it works: We give it one number, k = 3, the number of groups to find. Each try starts from three random photos as centers. Every photo joins its nearest center, then every center moves to the mean of its photos, until no center moves anymore. In our fifth try, two centers started in the city. One got squeezed out and took over the coast, while the coast center climbed into the mountains. After nine rounds the groups were exactly the three trips, all 600 photos. Try seven began the same way but got stuck: the city cut in two (50 and 200 photos) and one group of 350 for the coast plus the mountains, with a total squared distance 4.4 times larger. So the program makes ten tries and keeps the tightest. Nine of ten found the trips, and all ten together took 0.035 seconds on our laptop. Why it matters: It needs no answers, so it finds groups in data nobody has labeled. It is one of the top 10 algorithms in data mining, on the same list as naive Bayes from part 16. The vector search library FAISS uses k-means to split huge collections of vectors into groups, so a search only checks the nearest few. The speech model HuBERT learned by predicting groups that k-means found. Every number in the video comes from the real run of the program shown. #machinelearning #ai #kmeans #coding #python

Comments

Comments from the original post on TikTok

No comments yet