About K-Means Clustering Visualizer
This k-means clustering visualizer is free, needs no sign-up and runs in your browser, so your points are never uploaded. Tap the plot to add points, load a sample dataset or paste a CSV of x and y values, choose the number of clusters k, and press Step to watch the two halves of the algorithm: every point joins its nearest centroid, then each centroid moves to the mean of its points.
Run to convergence finishes the job, and the readout shows the inertia (the sum of squared distances to the centroids), the number of steps and the silhouette score. An elbow plot of inertia against k, with each point the best of four runs, helps you decide how many clusters the data supports.
K-means is the most widely used clustering algorithm, and its behaviour is easiest to learn by poking at it. Try the same data with random initialisation and with k-means++, ask for the wrong number of clusters, or feed it two moons and watch where a method built on round clusters goes wrong.
How to use K-Means Clustering Visualizer
- Pick a sample dataset, tap the plot to add points of your own, or paste x,y lines in the CSV box and press "Use these points".
- Set the number of clusters k, and choose k-means++ or random initialisation.
- Press Step. The first press assigns each point to its nearest centroid; the next moves each centroid to the mean of its points.
- Keep stepping, or press "Run to convergence", until the assignment stops changing.
- Read the inertia and the silhouette score, and look at the elbow plot to judge whether k is a good choice.
- Press "New start" to try a different random starting position, and see whether the clusters change.
Features
- Step-through mode that separates the assign step from the update step.
- Run to convergence with a clear converged message.
- k-means++ and random initialisation, with a repeatable seed and a New start button.
- Tap or click to add points, five sample datasets and CSV input for up to 3,000 points.
- Inertia, step count and mean silhouette score, updated as you go.
- An elbow plot of inertia for k from 1 to 10, with a marker at your k and the sharpest bend named.
- Touch-friendly canvas that scales to your screen and keeps vertical page scrolling working.
The k-means algorithm
K-means looks for k centroids that make the total squared distance from each point to its nearest centroid as small as possible. That quantity is the inertia, also called the within-cluster sum of squares. The algorithm alternates two steps until no point changes cluster. Each step can only lower the inertia, so it always converges, but only to a local minimum.
K-means++ chooses the starting centroids one at a time, giving each remaining point a probability proportional to the square of its distance to the nearest centroid already chosen. This spreads the starting centroids out and usually gives a better final result than picking random points.
inertia = sum over points of ||x - centroid(x)||^2
assign: c(x) = the centroid nearest to x
update: centroid_j = mean of the points assigned to j
silhouette(x) = (b - a) / max(a, b)Worked examples
Three blobs of 40 points, k = 3 gives inertia 13461.8, silhouette 0.713
The run converged in 2 assign steps and each blob ended up in its own cluster.
The same data for k = 1, 2, 3, 4 gives 116309, 57235, 13462, 11001
Inertia falls steeply until k = 3 and only slowly after that. That bend is the elbow, and it matches the three groups.
Good to know
What the silhouette score tells you
For each point, a is the mean distance to the other points in its own cluster and b is the mean distance to the points in the nearest other cluster. The silhouette is (b - a) divided by the larger of the two, so it runs from -1 to 1. Near 1 means the point sits well inside its cluster, near 0 means it is on a border, and negative means it is probably in the wrong cluster.
The tool reports the average over all points. Unlike inertia it does not fall automatically as k grows, so it can point to a best k directly. It needs at least two clusters.
Where k-means goes wrong
K-means assumes clusters are roughly round and similar in size, because it assigns points by straight-line distance to a centre. It cannot separate two interlocking moons or a ring around a core; try the Two moons and Circles samples to see it cut them with a straight line. The result also depends on where it starts, so run it more than once. The elbow plot here uses the best of four starts at each k to reduce that noise.
Privacy: how it works
- The points and the clustering stay in your browser tab. Nothing is sent to Ulkaa or anyone else.
Tips
- Scale your features first when they have very different units. K-means uses raw distance, so a column with a large range dominates.
- If the elbow is not clear, check the silhouette score for several values of k.
- An empty cluster keeps its previous centroid in this tool, so a bad start can leave a cluster unused. Use New start or k-means++.
- Adding a few outliers can drag a centroid away, because the mean is not robust. Tap far from the others to try it.
Frequently asked questions
Is it really free?
Yes. There is no price, no trial and no credit card. Ulkaa Tool does the work with your own device, so there is no server bill to pass on to you.
Do I need an account?
No. There is no sign-up and no login. Open the page and use it. An Ulkaa account is not needed for anything on this tool.
Does it run in my browser?
Yes. Your points are processed by code running in your browser tab, on your own device.
Is my data uploaded?
No. Your points are never sent to Ulkaa or to anyone else. You can check this yourself by watching the Network tab in your browser developer tools while you use the tool.
What is k-means clustering?
An algorithm that groups points into k clusters by repeating two steps: assign each point to its nearest centroid, then move each centroid to the mean of its points. It stops when the assignments no longer change.
How do I choose k?
Use the elbow plot to find where adding clusters stops lowering the inertia much, and check the silhouette score. Both are guides, and domain knowledge should have the last word.
What is inertia in k-means?
The sum of squared distances from each point to the centroid of its cluster. It is the quantity k-means tries to minimise, and it always falls as k increases.
What is k-means++?
A way of choosing the starting centroids so that they are spread out. It usually reaches a lower inertia than random starts and needs fewer steps.
Why do I get different clusters each time?
K-means only finds a local minimum, which depends on the starting centroids. Press New start to see other outcomes.
Why does k-means fail on the moons and circles?
It splits space with straight boundaries between centroids, so it favours round blobs. Density-based methods such as DBSCAN suit curved shapes.
What format does the CSV need?
Two numbers per line, x then y, separated by a comma, tab, semicolon or space. A header line is skipped, and any extra column is ignored. Up to 3,000 points are used.
Popular K-Means Clustering Visualizer pages
- Elbow Method CalculatorPlot inertia for k from 1 to 10 and spot the bend where more clusters stop helping.
- Silhouette Score CalculatorCluster your points and read the mean silhouette score.
- K-Means++ VisualizerWatch k-means++ pick starting centroids, then step to convergence.
- K-Means With Random InitialisationStart k-means from random data points and see how the outcome depends on the start.
- K-Means on the Two Moons DatasetCluster two interlocking half circles and see where k-means cuts them.
- K-Means on Concentric CirclesCluster a ring around a core and see why straight boundaries cannot separate them.
- K-Means Clustering From CSVPaste x,y data, choose k and cluster it in your browser.