|
K 均值聚类 (kmeans() ):
x <- rbind(matrix(rnorm(100, sd = 0.3) , ncol = 2) ,
matrix(rnorm(100, mean = 1, sd = 0.3) , ncol = 2))
cl <- kmeans(x, 2, 20)
plot(x, col = cl$cluster , pch=3, lwd=1)
points( cl$centers , col = 1:2 , pch = 7, lwd=3)
segments( x[ cl$cluster ==1 ,][ ,1] , x[ cl$cluster ==1 ,][ ,2] ,
cl$centers [1 ,1] , cl$centers [1 ,2])
segments( x[ cl$cluster ==2 ,][ ,1] , x[ cl$cluster ==2 ,][ ,2] ,
cl$centers [2 ,1] , cl$centers [2 ,2] ,
col=2) |
|