Skip to content
Advertisement

Get number of Clusters (3D)

I have a question about clustering. When you’re using k-nearest neighbour algorithm, you have to say, how many clusters you’re expecting. My problem is now, that I have some runs, where the number of clusters varies. I checked, and there are some methods how you can restrict, how many clusters you have, but these algorithms work for a two-dimensional problem. In my case, I have three features. Do you have an idea, of what algorithms I can use for a three-dimensional problem? I would be pleased if someone could help me because I also did some research by myself and I could not find anything. :)

Here for example it should locate two clusters, the one single point and the data row as the second cluster: first example

Here for example the second example, here I’m expectation the algorithm can find automatically three clusters, the long line, the short line and the single point: second example

Thanks. :)

Advertisement

Answer

As @ForceBru said in the comment you can use the k-means algorithm also for 3D data. I always use the sklearn.cluster.KMeans class when I have to deal with 3D points to cluster.

Take also a look at this link where you can find a simple example to get started:

enter image description here

The key part of the example provided in the link above is the following:

JavaScript

You can also try to use the DBSCAN algorithm (but I am not an expert with it). Take a look here.

EDIT

I studied a little bit the DBSCAN algorithm from the sklearn.cluster library and I have also found an interesting SO answer here. So, when the number of cluster is not known a-priori you can do something like this (I have tried to reproduce your input):

JavaScript

Here is what I get from the code above: enter image description here

Try to study the DBSCAN parameters from the documentation and then adjust them to meet your goals.

Finally, here is a tons of other clustering algorithms, take a look at it!

Hope it helps!

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement