[R] kmeans

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 3 19:38:17 CEST 2003


On Tue, 3 Jun 2003, Luis Miguel Almeida da Silva wrote:

>  I was working with kmeans from package mva and found some strange
> situations. When I run several times the kmeans algorithm with the same
> dataset I get the same partition. 

Why does that surprise you?

> I simulated a little example with 6
> observations and run kmeans giving the centers and making just one
> iteration. I expected that the algorithm just allocated the observations
> to the nearest center but think this is not the result that I get...

That's not what the documentation says it does:

     The data given by `x' is clustered by the k-means algorithm. When
     this terminates, all cluster centres are at the mean of their
     Voronoi sets (the set of data points which are nearest to the
     cluster centre).

which is true in your example.  It has run one iteration of re-allocation; 
as you can see by reading the source code or the reference.

[...]

-- 
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