
This is quite usual with kmeans as the algorithm may find different 
minima every time you call it.

If you want the same clusters every time you should set the same seed 
before runing kmeans, e.g.

set.seed(222)
kmeans.dem5 <- kmeans(demdata,7)


set.seed(222)
kmeans.dem5 <- kmeans(demdata,7)

etc

Cheers,

Marcelino


At 10:33 31/03/2011, Andy Wilson wrote:
>Hi all,
>I'm using an example (p213) in Hengl's A Practical Guide to 
>Statistical Mapping (an excellent book btw) as the basis to use 
>fuzzy k-means for the unsupervised extraction of landforms from land 
>surface parameter rasters. I've found that the classes are not 
>reproducible. When I run the same code on the same data 5 times I 
>wont get the same clusters every time - sometimes the same, but 
>sometimes there will be different numbers of cells attributed to 
>each class. Is this to be expected from fuzzy k-means or could this 
>be a problem with my approach.
>
>grids50m <- readGDAL("ELEV.asc")
>LSP.list <- c("RELELEV.asc", "PROFILE.asc")
>rsaga.sgrd.to.esri(in.sgrds=set.file.extension(LSP.list, ".sgrd"), 
>out.grids=LSP.list, prec=4, out.path=getwd())
>
>for(i in 1:length(LSP.list)){
>  grids50m@data[strsplit(LSP.list[i], ".asc")[[1]]] <- 
> readGDAL(LSP.list[i])$band1
>}
>pc.dem <- prcomp( ~ RELELEV+PROFILE, scale=TRUE, grids50m@data)
>demdata <- as.data.frame(pc.dem$x)
>
>kmeans.dem5 <- kmeans(demdata,7)
>grids50m$kmeans.dem5 <- kmeans.dem5$cluster
>grids50m$landform5 <- as.factor(kmeans.dem5$cluster)
>
># Initiate a raster to load the cluster data into
>r_class7 <- r_elev
># Extract the landform data into a vector
>v_class7 <- as.numeric(grids50m$landform5)
># Load the landform data into the raster
>r_class7 <- setValues(r_class5, v_class5)
>
>Many thanks for your advice...
>Andy Wilson
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo@r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo

____________________________________

Marcelino de la Cruz Rot
Depto. Biologia Vegetal
EUIT Agricola
Universidad Politecnica de Madrid

tel: 34 + 913365435
____________________________________  
	[[alternative HTML version deleted]]

