While browing videos on youtube I came across this video on K-means clustering. Once you get past the channel’s awful intro music
it was worth watching especially if you hadn’t heard of clustering before and have a curious nature.
For a statistician or researcher finding clusters of similar items in a large dataset is an important activity.
In some datasets the expected number of clusters is based on the type of data collected so we simple want to split the data into these clusters. In other datasets the number of clusters is not obvious so we need to find the optimum number first and from a programmers perspective that is the interesting and challenging part of the algorithm which is why I decided to see what I could do.
The video describes a visual approach, the ‘elbow method’ and my first challenge was to program an algorithm to do this. Later research described another algorithm the 'silhouette score` and my solution combines both algorithms.
Anyway after that long introduction here is the sketch, enjoy ![]()
(The fully documented source code is here)