About K-Means With Random Initialisation
This demo starts k-means from randomly chosen data points instead of k-means++. Step through, then press New start to compare different outcomes on the same data. It is free, needs no sign-up and runs in your browser, so nothing you enter is uploaded.
With random starts, two centroids can begin in the same group while another group has none. The algorithm then takes more steps, and can settle in a worse local minimum, for example one centroid shared between two groups while a third group is cut in half.
Try several starts and read the inertia each time. The lowest inertia is the best clustering found. This is why practical k-means implementations run many starts and keep the best.
How to use K-Means With Random Initialisation
- 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.
Worked examples
Three blobs, random start, k = 3 gives best of 5 starts: inertia 13461.8
A single unlucky start can end with a higher inertia than this.
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.
Why does random initialisation give different results?
K-means converges to a local minimum that depends on the starting centroids. Different starts can reach different minima.
How many times should I run k-means?
Ten or more starts are common. Keep the one with the lowest inertia.
More K-Means Clustering Visualizer pages
- K-Means Clustering VisualizerWatch k-means assign points and move centroids, one step at a time, on your own data.
- 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 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.