K-Means
- Label
- No label.
- Center
- A mean centroid.
- Distance
- Euclidean.
- Complexity
- O(n·k·d·i)
Loading…
K-Means assigns each row to a cluster when the table has no label, so the groups come from the features alone. KNN assigns a label from the nearest labeled rows, and it needs that class column before it can classify.
Choose whether the table has a label.
This is a choice, not a measured winner.
K-Means and KNN answer different questions; K-Means groups rows when the class column is absent, and KNN assigns a class to a new row when that column is known; adjusted Rand and hold-out accuracy are both shown because each one measures its own job.
Does the table have a label?
A class column to assign, instead of clusters from the features alone.
On Iris Flowers (150 rows and 4 features), K-Means with k=3 recovers held-out species at adjusted Rand 0.620 and silhouette 0.460. KNN with 5 neighbors scores accuracy 0.921 and macro F1 0.922 on a stratified 25% hold-out of 38 rows. The K-Means picture colors every row by cluster. The KNN picture uses that same PCA plane and colors every row by the prediction, which includes the 112 rows the classifier trained on.
On Iris, K-Means reports silhouette 0.460 and adjusted Rand 0.620 against the held-out species column, while KNN reports hold-out accuracy 0.921 and macro F1 0.922, and those scores are not the same metric.


The link loads the Iris sample. K-Means is set to k=3. KNN is set to 5 neighbors, uniform weights, and a 25% hold-out. Run is still required.
On Wine (UCI wine recognition) (178 rows and 13 features), K-Means with k=3 recovers held-out wine_class at adjusted Rand 0.897 and silhouette 0.285. KNN with 5 neighbors scores accuracy 0.933 and macro F1 0.931 on a stratified 25% hold-out of 45 rows. The K-Means picture colors every row by cluster. The KNN picture uses that same PCA plane and colors every row by the prediction, which includes the 133 rows the classifier trained on.


On Customer Segments (200 rows and 5 features), K-Means with k=4 recovers held-out segment at adjusted Rand 0.763 and silhouette 0.368. KNN with 5 neighbors scores accuracy 0.860 and macro F1 0.853 on a stratified 25% hold-out of 50 rows. The K-Means picture colors every row by cluster. The KNN picture uses that same PCA plane and colors every row by the prediction, which includes the 150 rows the classifier trained on. The classification tool does not load this sample; the published KNN run used the segment column that ships with the table.


| Dataset | Method | Score | Detail |
|---|---|---|---|
| Iris Flowers | K-Means | adjusted Rand 0.620 | silhouette 0.460 |
| Iris Flowers | KNN | accuracy 0.921 | macro F1 0.922, 38 test rows |
| Wine (UCI wine recognition) | K-Means | adjusted Rand 0.897 | silhouette 0.285 |
| Wine (UCI wine recognition) | KNN | accuracy 0.933 | macro F1 0.931, 45 test rows |
| Customer Segments | K-Means | adjusted Rand 0.763 | silhouette 0.368 |
| Customer Segments | KNN | accuracy 0.860 | macro F1 0.853, 50 test rows |
K-Means assigns each row to a cluster when the table has no label, so the groups come from the features alone. KNN assigns a label from the nearest labeled rows, and it needs that class column before it can classify.
This is a choice, not a measured winner.
On Iris, K-Means reports silhouette 0.460 and adjusted Rand 0.620 against the held-out species column, while KNN reports hold-out accuracy 0.921 and macro F1 0.922, and those scores are not the same metric.
Method: StandardScaler, drop constant columns. Comparison code version 8fbe69461da4 (scripts/seo/build_compare_runs.py). scikit-learn 1.4.2. Seed 42. The K-Means numbers are the published explore run, code version 3e4afc4b4352 (scripts/seo/build_explore_artifacts.py), computed on 2026-11-02. The class column was held out of every fit. Iris Flowers: UCI Machine Learning Repository, Iris (Fisher, 1936). License: CC BY 4.0. Wine (UCI wine recognition): UCI Machine Learning Repository, wine recognition. License: CC BY 4.0. Customer Segments: Synthetic customer records bundled with this site. License: Generated for demos; no external license.
Results computed, published, and last updated on 2026-11-03.
The comparison sentences are filled from these published runs by a fixed template, so the scores can be checked against the same datasets in the tool.
Maintainer: nikolaou1982.
Contact: nick1982100@gmail.com.