in r programming environment, using standard implementation of kmeans algorithm (type: help(kmeans)). appears cannot initialize starting centroids. specify kmeans algorithm give me 4 clusters , pass vector coordinates of starting centroids.
- is there implementation of
kmeansallow me pass initial centroid coordinates?
yes. implementation mention allows specify starting positions. pass them in through centers parameter
> dat <- data.frame(x = rnorm(99, mean = c(-5, 0 , 5)), y = rnorm(99, mean = c(-5, 0, 5))) > plot(dat) > start <- matrix(c(-5, 0, 5, -5, 0, 5), 3, 2) > kmeans(dat, start) k-means clustering 3 clusters of sizes 33, 33, 33 cluster means: x y 1 -5.0222798 -5.06545689 2 -0.1297747 -0.02890204 3 4.8006581 5.00315151 clustering vector: [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 [51] 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 within cluster sum of squares cluster: [1] 58.05137 73.81878 52.45732 (between_ss / total_ss = 94.7 %) available components: [1] "cluster" "centers" "totss" "withinss" "tot.withinss" "betweenss" [7] "size"
Comments
Post a Comment