Agglomerative Clustering in Matlab

Kevin_TA picture Kevin_TA · Nov 4, 2011 · Viewed 12.8k times · Source

I have a simple 2-dimensional dataset that I wish to cluster in an agglomerative manner (not knowing the optimal number of clusters to use). The only way I've been able to cluster my data successfully is by giving the function a 'maxclust' value.

For simplicity's sake, let's say this is my dataset:

X=[ 1,1;
    1,2;
    2,2;
    2,1;
    5,4;
    5,5;
    6,5;
    6,4 ];

Naturally, I would want this data to form 2 clusters. I understand that if I knew this, I could just say:

T = clusterdata(X,'maxclust',2);

and to find which points fall into each cluster I could say:

cluster_1 = X(T==1, :);

and

cluster_2 = X(T==2, :);

but without knowing that 2 clusters would be optimal for this dataset, how do I cluster these data?

Thanks

Answer

Amro picture Amro · Nov 5, 2011

The whole point of this method is that it represents the clusters found in a hierarchy, and it is up to you to determine how much details you want to get..

agglomerative dendogram

Think of this as having a horizontal line intersecting the dendrogram, which moves starting from 0 (each point is its own cluster) all the way to the max value (all points in one cluster). You could:

  • stop when you reach a predetermined number of clusters (example)
  • manually position it given a certain height value (example)
  • choose to place it where the clusters are too far apart according to the distance criterion (ie there's a big jump to the next level) (example)

This can be done by either using the 'maxclust' or 'cutoff' arguments of the CLUSTER/CLUSTERDATA functions