728x90

kmeans(data, centers) : centers - 군집의 갯수 k

 

install.packages("rattle")
library(rattle) #wine 데이터 세트 사용을 위한 라이브러리 불러오기

df = scale(wine[-1]) #데이터 스케일링
set.seed(Sys.Date())

fit.km = kmeans(df, 3, nstart = 25) #K-means cluster

fit.km$size #k개의 점과 가장 가까운 데이터의 갯수
fit.km$center #k개의 점에 대한 위치값

plot(df, col = fit.km$cluster) #K-means cluster 결과 그래프 출력(시각화)
points(fit.km$center, col = 1:3, pch = 8, cex = 1.5) #cluster k개의 점에 대한 표시
728x90