ARBIMETRA LAB
K-Means Clustering
Groups rows around K centroids, with inertia, assignments and an elbow plot.
What it does
Groups rows around K centroids, with inertia, assignments and an elbow plot.
Use it to find compact groups in numeric data.
Data you need
- Two or more numeric variables
- K
Supported data: Numeric. Level: Beginner.
Formula and method
min Σₖ Σ_{x∈Cₖ} ‖x − μₖ‖²
Lloyd's algorithm alternates between assigning rows to the nearest centroid and recomputing centroids, starting from k-means++ or random seeds. Ten restarts are run and the lowest inertia is kept.
Assumptions
- Clusters are roughly spherical and similar in size
Input checks
- More rows than clusters
- Fixed random seed
How to read the result
Read the centroids and silhouette score.
Worked example
Illustrative run on Fisher iris measurements. These figures are the actual output of this model on that example, and they say nothing about your own data.
- Inertia = 139.8205, silhouette = 0.4599.
- A silhouette of 0.4599 indicates moderate separation.
Limitations
- K-means always returns K clusters, even without real groups
Numerical validation
Validated 15 of 15 automated checks passed, including numerical results, invalid input, missing values, small samples, constant variables, charts and the interpretation text.
| Check | Reference | Result | Abs. error | Tolerance | Source |
|---|---|---|---|---|---|
| Inertia equals distances to centroids | 78.85144143 | 78.85144143 | 1.4e-14 | 1e-6 | Independent NumPy calculation |
| Fisher iris known optimum | 78.85144143 | 78.85144143 | 0.0e+0 | 1e-4 | Widely published optimum for K = 3 |
| Centroids are cluster means (Lloyd fixed point) | 0 | 0 | 0.0e+0 | 1e-6 | Independent NumPy calculation |
Computed with python 3.13.2, numpy 2.2.5, scipy 1.14.1, pandas 2.3.3, statsmodels 0.14.4, scikit-learn 1.7.0, in your browser. A passing check confirms the listed comparison only. It does not make any result suitable for your data, and it is not a claim of equivalence with other statistical software.
Questions
How do I choose K?
Use the elbow plot, the silhouette score and subject knowledge.
ARBIMETRA LAB is an educational and research tool. Results should be checked by the researcher and are not professional advice.
