Re: Question - Cluster Analysis

*To*: mathgroup at smc.vnet.net*Subject*: [mg89836] Re: Question - Cluster Analysis*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Sun, 22 Jun 2008 03:23:21 -0400 (EDT)

On 6/21/08 at 5:29 AM, patrick.bernhard at gmx.net (Steve Mahoney) wrote: >I have a question regarding hierarchical cluster analysis. One >measure to determine the number of clusters is the so called elbow >criteria, which is just a list of the single distances between the >clusters. >These values are inside the results from the Agglomerate function, >but I am not able to extract them to a list. >data = {{1, 2, 2}, {1, 3, 3}, {2, 4, 2}, {5, 4, 3}, {5, 4, 4}, {7, >6, 7}}; >Agglomerate[data] >Cluster[Cluster[ >Cluster[Cluster[{1, 2, 2}, {1, 3, 3}, 2, 1, 1], {2, 4, 2}, 3, 2, 1], >Cluster[{5, 4, 3}, {5, 4, 4}, 1, 1, 1], 10, 3, 2], {7, 6, 7}, >17, 5, 1] >--> now I have to extract the values manually >elbowcriterium = ListLinePlot[{17, 10, 3, 2, 1}] >--> suggesting three clusters It looks like pattern matching and ReplaceRepeated is what you need here. That is, In[33]:= Flatten[ Agglomerate[data] //. Cluster[b_, _, a_, _, _] -> {a, b}][[;; -3]] Out[33]= {17,10,3,2,1} appears to yield the result you want.