Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. 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 have a set of user queries from a search engine that I want to cluster. The only clustering algorithm I have come across so far is the K-means clustering algorithm, which requires defining the number of clusters up front. But in this case, I do not know how many clusters exist in the data. Is there any clustering algorithm that performs clustering without predefining the number of clusters?

share|improve this question


DBSCAN requires two parameters: distance (eps) and the minimum number of points required to form a cluster (minPts).

share|improve this answer

There are several techniques that allow you to cluster unsupervised data. K-means is probably the most famous one. But as you have already seen, most k-means algorithms require the number of clusters to be specified in advance.

Nevertheless, at least two kinds of algorithms might suit your needs:

  1. Connectivity based clustering (hierarchical clustering);
  2. Density-based clustering (such as DBSCAN or OPTICS).

By the way, there is a similar question in StackOverflow.

Have fun!

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.