Kmeans without knowing the number of clusters?

26,341

Solution 1

One approach is cross-validation.

In essence, you pick a subset of your data and cluster it into k clusters, and you ask how well it clusters, compared with the rest of the data: Are you assigning data points to the same cluster memberships, or are they falling into different clusters?

If the memberships are roughly the same, the data fit well into k clusters. Otherwise, you try a different k.

Also, you could do PCA (principal component analysis) to reduce your 50 dimensions to some more tractable number. If a PCA run suggests that most of your variance is coming from, say, 4 out of the 50 dimensions, then you can pick k on that basis, to explore how the four cluster memberships are assigned.

Solution 2

Take a look at this wikipedia page on determining the number of clusters in a data set.

Also you might want to try Agglomerative hierarchical clustering out. This approach does not need to know the number of clusters, it will incrementally form clusters of cluster till only one exists. This technique also exists in SciPy (scipy.cluster.hierarchy).

Solution 3

One interesting approach is that of evidence accumulation by Fred and Jain. This is based on combining multiple runs of k-means with a large number of clusters, aggregating them into an overall solution. Nice aspects of the approach include that the number of clusters is determined in the process and that the final clusters don't have to be spherical.

Solution 4

There are visualization that should hint good parameters. For k-means you could visualize several runs with different k using Graphgrams (see the WEKA graphgram package - best obtained by the package manager or here. An introduction and examples can also be found here.

Share:
26,341
Legend
Author by

Legend

Just a simple guy :)

Updated on May 15, 2020

Comments

  • Legend
    Legend almost 4 years

    I am attempting to apply k-means on a set of high-dimensional data points (about 50 dimensions) and was wondering if there are any implementations that find the optimal number of clusters.

    I remember reading somewhere that the way an algorithm generally does this is such that the inter-cluster distance is maximized and intra-cluster distance is minimized but I don't remember where I saw that. It would be great if someone can point me to any resources that discuss this. I am using SciPy for k-means currently but any related library would be fine as well.

    If there are alternate ways of achieving the same or a better algorithm, please let me know.

  • Rob Neuhaus
    Rob Neuhaus almost 13 years
    What is the link between the number of dimensions and the number of clusters? I can easily build a 1 dimensional distribution with k clusters for arbitrary K.
  • Fred Foo
    Fred Foo almost 13 years
    "If the memberships are roughly the same" -- this assumes the data is divided evenly into clusters, which is quite a strong assumption.
  • max
    max almost 8 years
    What do you mean by "the same cluster memberships"? Do you compare the clustering on the training folds with the clustering on the test fold? If so, I'm not sure how you can compare them, since they have completely non overlapping data points.