About K-Means on the Two Moons Dataset
This page runs k-means with two clusters on the classic two moons dataset, where the true groups are curved and interlock. It is free, needs no sign-up and runs in your browser, so nothing you enter is uploaded.
K-means assigns each point to the nearest centroid, so the boundary between two clusters is always a straight line halfway between the centroids. The two moons cannot be separated by a straight line, so k-means splits each moon across the middle instead of keeping each moon whole.
The inertia is low, and the silhouette looks respectable, so these numbers do not warn you that the grouping is wrong. Only looking at the plot, or knowing the shape of the data, does. For curved clusters try density-based clustering or spectral clustering.
How to use K-Means on the Two Moons Dataset
- 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
Two moons of 50 points each, k = 2 gives inertia 23806, silhouette 0.492
A reasonable-looking score for a clustering that does not match the true shapes.
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 can k-means not cluster two moons?
Its boundaries are straight lines between centroids, and it favours round clusters of similar size.
What clustering method works on moons?
DBSCAN or spectral clustering, which follow density or connectivity instead of distance to a centre.
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 With Random InitialisationStart k-means from random data points and see how the outcome depends on the start.
- 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.