3
在R編程環境中,我目前使用kmeans
算法的標準實現(類型:help(kmeans)
)。看起來我無法初始化起始質心。我指定kmeans
算法給我4簇,我想通過起始質心的矢量座標。R kmeans初始化
- 是否有執行
kmeans
允許我傳遞初始質心座標?
在R編程環境中,我目前使用kmeans
算法的標準實現(類型:help(kmeans)
)。看起來我無法初始化起始質心。我指定kmeans
算法給我4簇,我想通過起始質心的矢量座標。R kmeans初始化
kmeans
允許我傳遞初始質心座標?是的。您提到的實施允許您指定起始位置。你通過centers
參數centers
參數
> 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 with 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 by 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"
''中心'參數應該讓你這樣做。 – Marius 2013-05-06 00:25:33