2016-10-05 2 views
-5

R에서 계층 적 클러스터링을 실행했으며 어떤 관찰이 어떤 클러스터에 속할 수 있습니까? 감사! 당신이 NbClust에서 최적화 결과에 관심이 있다면 각각의 번호가 데이터 매트릭스의 각각의 행에 대해 클러스터 번호입니다어느 관측치가 어떤 클러스터에 속하는지 어떻게 알 수 있습니까?

### Hierarchical Clustering 
d <- dist(EMEA_2, method = "euclidean") # distance matrix 
fit <- hclust(d, method="complete") 

### Decide bet number of clusters 
library(knitr) 
library(NbClust) 

nc<-NbClust(data = EMEA_2, distance = "euclidean", min.nc=2, max.nc=15, method = "complete", index = "db", alphaBeale = 0.1) 

groups <- cutree(fit, k=2) # cut tree into 2 clusters 

### Get group means and number of frequencies within each cluster 
a2<-aggregate(EMEA_2, list(groups),mean) 
a4<-data.frame(Cluster = a2[,1], Freq = as.vector(table(groups)), a2[,-1]) 
+0

코드는 어디에 있습니까? – mtoto

+0

@mtoto 방금 고마워했습니다. –

+1

'str (nc)'를 보면'stats :: kmeans'처럼 data.frame 'clusters'가있을 것이라고 생각합니다. 그러면 당신은'nc $ clusters $ '나 그곳에있는 이름으로 액세스 할 수 있습니다. –

답변

1

, 당신은 nc$Best.partition에 그것을 발견 할 것이다. 20x10 데이터 매트릭스 예

> nc$Best.partition 
[1] 1 2 3 4 5 1 3 5 1 1 4 1 4 1 5 1 5 1 4 2 

위한

.