3. K-means
• K-means法の手順
① 事前にクラスタ数kと繰り返し回数nを決めておく。
② step1:クラスタの中心点を、対象データの中からランダムにk
個選び出す。
③ step2:データごとに各クラスタの中心点との距離を求め、最も
近くに中心点があるクラスタに割り当てる
④ step3:クラスタごとに、割り当てられたデータの平均値を求め、
新たな中心点として採用する。
⑤ クラスタに割り当てるデータに変化がなくなる(=各クラスタの
中心点が定まる)まで、step2からstep3を繰り返す。ただし、繰
り返し数がnに達した場合はその時点で終了する。
4. K-meansの例
require(graphics)
# 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")
(cl <- kmeans(x, 2))
plot(x, col = cl$cluster)
points(cl$centers, col = 1:2, pch = 8, cex = 2)
5. K-means++
• 文法:
• kmeanspp(data, k = 2, start = "random", iter.max = 100, nstart = 10, ...)
• Arguments
• data:an N ¥times d matrix, where N are the samples and d is the
dimension of space.
• k:number of clusters.
• start:first cluster center to start with
• iter.max:the maximum number of iterations allowed
• nstart:how many random sets should be chosen?
• ...:additional arguments passed to kmeans