I am trying to cluster trend data similar to that created by

data = Table[
   RandomReal[{-1, 1}, 20] + 10 offset, {offset, 1, 10, 1}] // Flatten

This data is highly simplified and has a fixed number of values for each cluster. In general this will not be true but the number of possible clusters will be known in advance. The noise level may also vary for each cluster and the average distance between clusters may vary.

Automatic clustering by

ClusteringComponents[data, 10]

is nearly correct but is not stable. In general, I am looking for methods to pre-determine the CritionFunction and DistanceFunction, etc. from the data to stabilize the clustering.

I have previously seen a similar problem discussed here but I cannot locate it via search. Probably just the wrong keywords.


1 Answer 1


Not sure what you mean by "nearly correct but is not stable". Have you tried FindClusters? e.g.

FindClusters[data, Method -> "DBSCAN"] // ListPlot

enter image description here

  • $\begingroup$ I have tried FindClusters. This is essentially the same functionality as in ClusteringComponents. Not stable means that with default settings the result is not reproducible given the variation provided by RandomReal with limits +/-1 and the offset of 10 per step/cluster. $\endgroup$
    – OpticsMan
    Oct 14, 2020 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.