Regression & multivariate

K-Means Clustering Online: Elbow Plot, Silhouette and Cluster Plot

Split your rows into k groups of similar values. Paste your data, choose the variables and the number of clusters, and get the cluster centres, sizes and the share of variance explained, an elbow plot, silhouette widths and the Calinski–Harabasz index to help choose k, and a cluster plot on the first two principal components.

✅ No login needed100% freeRuns in your browserYour data stays on your device
K-Means Clustering Calculator✅ Free · no login📚 Cite this tool
Your data never leaves your PC. Your data is analysed on your own computer or phone, even when you upload a CSV or Excel file. Nothing is uploaded, stored or seen by Codanics, and no login is needed.

Variables to include

  • PriceFree, no login or sign-up needed
  • Your dataProcessed in your browser, never uploaded
  • Works onPhone, tablet or computer, any modern browser
  • Made byDr. Muhammad Aammar Tufail, Codanics
  • Published17 November 2026
  • Last updated16 November 2026

📚 How to cite this tool

This tool is free. If it helped your thesis, paper, report or assignment, please cite it. It keeps the tools free and helps other students find them.

Citation · APA 7th edition

Tufail, M. A. (2026). K-means clustering calculator: elbow plot, silhouette and cluster plot [Online tool]. Codanics. Retrieved 16 November 2026, from https://codanics.com/tools/k-means-clustering-calculator/

In-text citation: (Tufail, 2026) · Narrative: Tufail (2026)

The access date is today’s date, filled in automatically. Author: Muhammad Aammar Tufail. Published 17 November 2026.

🚀 Follow Codanics channel on WhatsApp for more updatesNew free tools, scholarships, PhD positions and research tips, straight to your phone. Free lessons on YouTube too.

How to use the K-Means Clustering Calculator

  1. Paste your table or use Paste from Excel / Upload CSV / Excel, with column names in the first row and one row per sample. The iris data (150 flowers, 4 measurements) is loaded as an example; its Species column is used only to check the clusters afterwards.
  2. Tick the variables to cluster on and keep z-scores unless all variables share the same unit. Optionally pick a column with known groups to compare against.
  3. Choose the number of clusters k and click Run k-means. Check the elbow plot, the average silhouette and the Calinski–Harabasz index to see whether another k fits better, and change k if needed.
  4. Download the cluster plot, the elbow and silhouette plots, copy the table of centres into Word, and download your data with a cluster column added.

How k-means clustering works

K-means divides the rows into k clusters so that the sum of squared distances from each row to its cluster centre (the within-cluster sum of squares) is as small as possible. The algorithm places k starting centres, assigns each row to its nearest centre, moves each centre to the mean of its rows, and repeats until nothing changes. Because the result depends on the starting centres, the tool runs it many times (25 by default) from k-means++ starting points and keeps the best solution, then refines it with Hartigan’s single-row transfers, the criterion used by R’s default algorithm.

K-means is used to group farmers or respondents into typologies, sites by environmental variables, genotypes by traits, and customers or patients by profiles. It works best with continuous variables and roughly spherical, similar-sized clusters.

How many clusters should I choose?

  • Elbow plot: the total within-cluster sum of squares always falls as k grows. Choose the k after which the curve flattens (the “elbow”).
  • Average silhouette width: how well each row fits its own cluster compared with the nearest other cluster. Higher is better; above 0.5 is a reasonable structure, above 0.7 a strong one.
  • Calinski–Harabasz index: the ratio of between-cluster to within-cluster variance, adjusted for k and n. Higher is better.
  • Meaning: the clusters must be interpretable and useful for your question. A dendrogram often helps too.

Formulas

Within-cluster SS: W = Σₖ Σ_{i ∈ k} ‖xᵢ − cₖ‖² cₖ = mean of the rows in cluster k Total SS: T = Σᵢ ‖xᵢ − x̄‖² Between SS: B = T − W Variance explained = B / T Calinski–Harabasz = [B / (k − 1)] / [W / (n − k)] Silhouette of a row: s = (b − a) / max(a, b) Hartigan transfer: move row i from cluster A to B if n_B/(n_B+1)·‖xᵢ−c_B‖² < n_A/(n_A−1)·‖xᵢ−c_A‖²

On the iris example with k = 3, the result is the same as R’s kmeans(scale(x), 3, nstart = 25): the same cluster sizes and the same total within-cluster sum of squares. Cluster numbers can differ between programs because they are arbitrary labels. Silhouette widths match cluster::silhouette().

How to report k-means clustering

K-means clustering (25 random starts) on the four standardised flower measurements produced three clusters of 50, 53 and 47 flowers. The clusters explained 76.7% of the total variance (average silhouette width = .46). Three clusters were chosen from the elbow plot and the silhouette widths.

Report the variables and standardisation, how you chose k, the number of starts, the cluster sizes and a table of centres. For a solid foundation in statistics, try the free ABC of statistics series, then the R with Aammar course.

Learn the statistics behind these numbers. Codanics has free statistics, R and Python lessons on YouTube and full courses for researchers.

Frequently asked questions

Why do I get different clusters each time in other software?

K-means starts from random centres, so a single run can end in a poor local solution. This tool uses a fixed random seed and many starts (25 by default) and keeps the solution with the lowest within-cluster sum of squares, so results are reproducible. Change the seed or increase the starts to check that the solution is stable.

Should I standardise before k-means?

Yes, if the variables are in different units. K-means uses Euclidean distance, so a variable measured in thousands would otherwise dominate the clustering. Z-scores are the usual choice.

Can I use k-means with categorical variables?

No. K-means needs numeric variables because it averages them. For categorical or mixed data, use methods such as k-modes or Gower distance with hierarchical clustering in R. Ordinal Likert scores are often treated as numeric, but interpret the results with care.

What does 'between SS / total SS' mean?

It is the share of the total variation that lies between the cluster centres, like R² in regression. Higher values mean more distinct clusters, but the value always increases with k, so do not choose k by this number alone.

Why is a cluster plot made on principal components?

With more than two variables, the clusters cannot be drawn directly. The plot projects the rows onto the first two principal components, which show as much of the variation as possible in two dimensions. Clusters can overlap on the plot but still be separated in other dimensions.

K-means or hierarchical clustering?

Use hierarchical clustering for smaller data sets when you want a tree and don’t know k. Use k-means for larger data sets or when you already have a good idea of k. A common approach is to choose k from a dendrogram and then refine the clusters with k-means.

Is my data uploaded?

No. K-means runs entirely in your browser. Pasted and uploaded data never leave your device.

Do I need to log in or create an account to use the K-Means Clustering Calculator?

No. There is no login, no sign-up and no email required. Open the page and start using it straight away, for free, on any device.

How do I cite this tool in my thesis or paper?

Use the citation box on this page. In APA 7th edition: Tufail, M. A. (2026). K-means clustering calculator: elbow plot, silhouette and cluster plot [Online tool]. Codanics. Retrieved [date you used it], from https://codanics.com/tools/k-means-clustering-calculator/. BibTeX, RIS (EndNote, Mendeley, Zotero), MLA, Harvard, Chicago and Vancouver formats are also available.

Free guides and courses from Codanics

More free tools

See all free Codanics tools → · Codanics on YouTube · WhatsApp channel

Made by Dr. Muhammad Aammar Tufail, Codanics. First published 17 November 2026, last updated 16 November 2026. Found a bug or have an idea for a new tool? Tell us on the WhatsApp channel or in the comments on YouTube. Results are for learning and planning; check important analyses with a statistician or your supervisor.