2013-07-08 8 views
-5

이 그래프를 생성 그래프 :이해 3 차원 kmeans 코드 아래

enter image description here

두 차원 항목이 각 클러스터의 중심이지만, 왜 중심이 그래프 생성되지 클러스터링?

그래프의 각 그룹은 다른 두 항목의 kmeans 클러스터를 생성합니까? 예를 들어 첫 번째 행에서 왼쪽에서 오른쪽으로 이동하면 "google"이 레이블이고 kmeans가 "so"와 "test"로 생성됩니다.

cells = c(1,1,1, 
      1,0,1, 
      1,0,1, 
      1,0,0, 
      1,1,1, 
      0,1,0, 
      0,1,1, 
      1,1,0, 
      0,0,1, 
      0,0,0, 
      1,1,1, 
      1,1,0, 
      1,0,1, 
      1,1,0, 
      1,0,1, 
      1,1,0, 
      1,0,1, 
      1,1,0, 
      1,0,1, 
      1,1,0, 
      1,0,1, 
      1,1,0, 
      1,0,1, 
      1,1,0) 
rnames = c("a1","a2","a3","a4","a5","a6","a7","a8","a9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24") 
cnames = c("google","so","test") 
x <- matrix(cells, nrow=24, ncol=3, byrow=TRUE, dimnames=list(rnames, cnames)) 
# run K-Means 
km <- kmeans(x, 8, 5) 
# print components of km 
print(km) 
# plot clusters 
plot(x, col = km$cluster) 
# plot centers 
pairs(jitter(x), col = cl$cluster) 
+1

'쌍 (지터 (x), col = km $ 클러스터)'을 사용해보십시오. –

+0

@ Jean V. Adams 감사하지만 게시 된 질문에 대한 설명이 필요합니다. –

+4

이 질문은 CrossValidated에 속하는 통계 결과를 해석하기 때문에 주제와는 거리가 먼 것처럼 보입니다. –

답변

3

중력을 그리지 않으므로. 당신의 earlier question에서 무게 중심이 명령에 의해 그려진했다 :

points(cl$centers, col = 1:5, pch = 8, cex = 2) 

이는 plot 기능에 의해 생성 된 플롯 각 중심 포인트를 추가했다. pairs()으로이 작업을 시도하면 작동하지 않습니다. 하지만 게시 한 코드에서이 작업을 시도해 보지 않으므로 어쨌든 왜 도심이 그려지는지 확신 할 수 없습니다.

pairs() 플롯에 포인트를 추가하는 것은 불행히도 수동 프로세스입니다. 문자 pairs()panel, lower.panelupper.panel 매개 변수를 사용하여 각 벡터 쌍에 대해 플롯하려는 것을 정확하게 지정할 수 있습니다. 여기서는 하위 메서드를 지정하여 정상적으로 점을 상단 패널에 표시하고 점을 중심에있는 점을 하단 패널에 표시합니다. 데이터 집합이 너무 작기 때문에

Amplified pairs plot, centroids added to lower panel

# I use the variable name "x" elsewhere, 
# renaming it here explicitly for clarity 
x.mat=x 

# I moved the "jitter" into this submethod, so you won't see it 
# in the main 'pairs()' call. I needed to do this to identify the source 
# column the data came from in low.panelfun. 
up.panelfun <- function(x,y,clust=cl$cluster,...){ 
    # this plots the main pairs plot 
    sapply(unique(clust), function(c){ points(jitter(x[clust==c]),jitter(y[clust==c]), col=c)}) 
} 

low.panelfun <- function(x,y,clust=cl$cluster,...){ 
    # this plots the main pairs plot 
    up.panelfun(x,y,clust) 

    # this finds the appropriate column the panel is related 
    # to and plots the centroids. 
    xi=which(length(x)==apply(x.mat, 2, function(v){sum(v==x)})) 
    yi=which(length(y)==apply(x.mat, 2, function(v){sum(v==y)})) 
    points(cl$centers[xi,],cl$centers[yi,], col = 1:5, pch = 8, cex = 2) 
} 

pairs(x.mat, col = cl$cluster 
     ,lower.panel=low.panelfun 
     ,upper.panel=up.panelfun 
) 
, 내가 클러스터가 좀 더 분명하게 결과를 몇 번 복제하여 데이터를 증폭하는 것이 유용하다고 :

# amplify clusters by replicating data a few times 
pairs(rbind(x.mat, x.mat, x.mat, x.mat), col = cl$cluster 
     ,lower.panel=low.panelfun 
     ,upper.panel=up.panelfun 
) 

이 모든 추가 작업을 고려하고 실제로 세 개의 플롯 만 필요로했을 때 각각의 변수 쌍에 대해 별도의 plot();points() 호출을 작성하는 것이 더 쉬웠을 것입니다.

+0

생성 된 그래프를 어떻게 읽어야합니까? 각각의 레이블 "google", "so", "test"는 다른 그래프와 관련하여 그 의미가 무엇입니까? –

+1

이것은 단지 일반적인 2 차원 산점도입니다. 'pairs()'함수는 가능한 모든 변수 쌍을 가져 와서 서로에 대해 그려줍니다. 쌍 함수에 대한 문서를 확인하십시오, 꽤 잘 설명되어 있습니다. –

+0

덕분에 나는이 유용한 것을 발견했다 : http://www.statmethods.net/graphs/scatterplot.html 섹션 : "산란계 매트릭스" –