# How to cluster the data? [duplicate]

I have a data that looks like below and I want to cluster them. What would be the best algorithm to apply for clustering such data.

Please give a clear explanation of what your problem is, what the data is, and what you want to learn from the data. We need this information to help you determine the best clustering algorithm!

A general baseline algorithms is the K-means algorithm (you can find it as a python function in the sci-kit learn package): http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html) Here, you specify the number of clusters. The algorithm performs 2 steps, iteratively:

1. Assign each point to the closest cluster (measured by the distance to the cluster mean)
2. Recalculate the cluster mean
3. Repeat 1 and 2 until there's no other need.
• If it worked, please mark my answer as the correct one! Jun 7, 2016 at 21:42

From the plot of the data it looks like the variable on y axis has only 1 value = 6. If this is the case, then you could use k-means clustering over only the x-axis variable.

The reason for this is that the clustering algorithm first creates a distance matrix of each data-point w.r.t. the others. Although various distance metrics are used commonly, for this discussion lets assume you'll be using the Euclidean distance. Since the y-axis does not change, the distance metric would not change whether you include y-axis or not. Hence, there is no point in including it in the clustering.

However, if the y-axis variable does vary but the variations are too small to be represented on the plot, then you should scale both x-axis and y-axis variables between 0 to 1 before clustering on them. That would allow you to use the y-axis variable to make clusters.