Build k-means from scratch in NumPy and read its results

9 steps · about 2 h 35 min · Intermediate

  1. StatQuest: K-means clustering (video, StatQuest with Josh Starmer (YouTube), 10 min)

    A short visual walkthrough of the assign-and-update loop and the elbow plot, so the code that follows makes sense.

  2. k-Means Clustering (video, Orange Data Mining (YouTube), 5 min)

    An interactive demo shows centroids moving step by step, which builds intuition for convergence.

  3. K-Means Clustering From Scratch (NumPy only) (tutorial, GitHub: JovaughnR, 25 min)

    Works the algorithm out by hand first, then turns each step into vectorised NumPy with WCSS.

  4. K-Means Clustering from Scratch in Python (tutorial, mlrefined.com, 25 min)

    Gives a clean, seeded implementation with separate assignment and update functions that you can compare with your own.

  5. K-Means Clustering Explained with Examples and Python (article, Being Neuron, 30 min)

    Builds k-means in NumPy, then reruns the same data in scikit-learn so you can check your version against the library.

  6. K-means clustering with NumPy (article, The Neural Base, 15 min)

    Covers the main pitfalls: unscaled features, sensitivity to initialization, k-means++ seeding and random restarts.

  7. Comparison of Methods to Inform K-Means Clustering (article, Towards Data Science, 15 min)

    Compares elbow-chosen and silhouette-chosen k on real data, so you see how the two methods can disagree.

  8. KMeans-Clustering-Elbow-Silhouette (repo, GitHub: moonmido, 20 min)

    A runnable scikit-learn project with scaling, SSE and silhouette curves to use as a check on your NumPy results.

  9. Implementing the k-means algorithm from scratch (article, Educative, 10 min)

    Closes with local minima and alternatives such as DBSCAN, so you know when k-means is the wrong tool.