[R] distance in kmeans algorithm?

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Jul 9 19:44:12 CEST 2006


You do realize that Mahalanobis distance is just Euclidean distance on 
some linear transformation of the variables?  So all you need to do is to 
transform the data you pass to kmeans to 'sphere' the Mahalanobis 
distance.

The K means *algorithms* do depend on Euclidean distance (e.g. in choosing 
the cluster centres as the centroids), so your initial question makes 
little sense.  You can of course use the criterion with other distances, 
but you need to develop other algorithms to do so.

On Sun, 9 Jul 2006, Arnau Mir wrote:

> Hello.
>
> Is it possible to choose the distance in the kmeans algorithm?
>
> I have m vectors of n components and I want to cluster them using kmeans
> algorithm but I want to use the Mahalanobis distance or another distance.
>
> How can I do it in R?
> If I use kmeans, I have no option to choose the distance.
>
> Thanks in advance,
>
> Arnau.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list