Is there any way that I can assure that kmeans always returns the same result for the same data by locking down the random number generator or anything else? David
David Bitner wrote:> Is there any way that I can assure that kmeans always returns the same > result for the same data by locking down the random number generator > or anything else? > > David >Try ?set.seed before your call to kmeans: # from ?kmeans # a 2-dimensional example x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2), matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2)) colnames(x) <- c("x", "y") # set seed for random number generator set.seed(42) cl.1 <- kmeans(x, 5, nstart = 25) set.seed(42) cl.2 <- kmeans(x, 5, nstart = 25) # check whether objects are identical all.equal(cl.1, cl.2) HTH, --sundar
On Tue, 28 Feb 2006, David Bitner wrote:> Is there any way that I can assure that kmeans always returns the same > result for the same data by locking down the random number generator > or anything else??set.seed> > David > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no