Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use kmeans for clustering a set of data. However, I have to specify the number of clusters. The problem is that sometimes I need 2 and other times I need 3 clusters.

  • Is there a clustering algorithm that could incorporate that feature in it?
share|improve this question
You may find this related question on number of clusters useful:… – Jeromy Anglim May 2 '11 at 8:14
Just to clarify, you are looking for a feature that will automate the determination of number of clusters? or are you simply looking to batch process the running of a set of cluster analyses where number of clusters are known? What is your current manual approach to deciding whether two or three clusters is appropriate? do you wish to continue to use this rule or are you interested in other procedures for determining number of clusters? – Jeromy Anglim May 2 '11 at 8:19

Simplest solution: do both and then check which gives best results...

share|improve this answer
What do you define as the best result? How do you suggest this should be automated as per user2721's question? – Jeromy Anglim May 2 '11 at 8:13
He indicates that sometimes he 'needs' 2 and sometimes 3. So apparently, he has some criterion, which he doesn't mention. It surely is not uncommon to run clustering over a set of possible cluster numbers, and then evaluate. – Nick Sabbe May 2 '11 at 8:30
@Jeromy Silhouette measure is quite usable, at least for start; it often offers clear minimum, so it is good for automatic optimization. – mbq May 2 '11 at 8:41

this is a great paper to start with:

Estimating the number of clusters in a data set via the gap statistics

It's really easy to implement something similary in any language.

share|improve this answer

You can have a look at "clues" method.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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