[R] distance in the function kmeans

Christian Hennig fm3a004 at math.uni-hamburg.de
Fri May 28 10:22:34 CEST 2004


On Fri, 28 May 2004, Uwe Ligges wrote:

> n.bouget wrote:
> 
> > Hi,
> > I want to know which distance is using in the function kmeans
> > and if we can change this distance. 
> > Indeed, in the function pam, we can put a distance matrix in
> > parameter (by the line "pam<-pam(dist(matrixdata),k=7)" ) but
> > we can't do it in the function kmeans, we have to put the
> > matrix of data directly ...
> > Thanks in advance,
> > Nicolas BOUGET
> 
> As the name says, kmeans() calculates *means* (centres) of clusters. It 
> does not any make sense to do that on distances ...
> 
> Uwe Ligges

That's not really true. There is an equivalent to the k-means target
criterion in terms of distances, and that uses squared Euklidean
distances. However, as far as I know, you cannot compute it directly in
R for any other distance. Using pam is the thing which comes closest.

Christian Hennig


***********************************************************************
Christian Hennig
Fachbereich Mathematik-SPST/ZMS, Universitaet Hamburg
hennig at math.uni-hamburg.de, http://www.math.uni-hamburg.de/home/hennig/
#######################################################################
ich empfehle www.boag-online.de




More information about the R-help mailing list