Skip to content
Advertisement

Clustering different sets of points with different linear relationships to each other in Python

I need to cluster groups of points with the same linear relationship, as per the code and figure below.

JavaScript

enter image description here

Obviously, I wouldn’t have the points that way; I would just have the following x and y.

JavaScript

enter image description here

Note the following: the points respect linear relationships with high slope, they present a slight separation from each other, and they all have the same slope, just with different intercepts.

How would you suggest I cluster these points? I thought about using PCA and clustering the main components with k-means, but I don’t know if there would be a more efficient way. In my real case I have more than three clusters and they have different distances from each other, even though they all have the same slope.

Advertisement

Answer

Take a look at all clustering algorithms scikit-learn offers : clustering algs.

Spectral clustering and Gaussian mixture should work for your use case.

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