Clustering: k-means and When It Fails, in Python
k-means matched 299 of 300 points on round clouds, but turned a small cloud of 40 into a cluster of 102.
Video #193 ยท Machine learning and data science
Steps in the video
Files
- check.py (23 lines)
- data.py (26 lines)
- run.py (24 lines)
Tested with
Python 3.12.15 | numpy==2.5.4, scikit-learn==1.9.1, scipy==1.18.1, joblib==1.6.0, narwhals==2.27.1, threadpoolctl==3.7.0, cloudpickle==3.1.2
What this does not show
Made-up two-dimensional points with a known answer; choosing k, scaling and other clustering methods are not shown.
Sources
- https://en.wikipedia.org/wiki/K-means_clustering
- https://pypi.org/pypi/numpy/json
- https://pypi.org/pypi/scikit-learn/json
- https://scikit-learn.org/stable/auto_examples/cluster/plot_kmeans_assumptions.html
- https://scikit-learn.org/stable/modules/clustering.html
- https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html
Learning IT by Example.