시작하기무료로 시작하기

높이에 따른 클러스터

이전 연습 문제에서는 미리 정해 둔 클러스터 개수(k)를 사용해 관측치를 클러스터로 묶었죠. 이번 연습에서는 덴드로그램의 시각적 표현을 활용해, 특정 최대 높이(h)를 기준으로 그 아래에서 형성되는 클러스터를 만들어요.

dendextend 라이브러리의 color_branches() 함수를 사용해 덴드로그램의 어느 높이에서든 형성되는 클러스터를 시각적으로 확인해 보세요.

축구 포지션 데이터 작업에서 이어진 hc_players 객체를 사용합니다.

이 연습은 강의의 일부입니다

R로 배우는 군집 분석

강의 보기

연습 안내

  • as.dendrogram() 함수를 사용해 hclust 결과로부터 덴드로그램 객체 dend_players를 만드세요.
  • 덴드로그램을 그리세요.
  • color_branches() 함수를 사용해 컷 높이를 20으로 설정하고, 클러스터별로 색이 입혀진 새로운 덴드로그램을 생성해 그리세요.
  • 위 단계를 높이 40으로 바꾸어 한 번 더 반복하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

library(dendextend)
dist_players <- dist(lineup, method = 'euclidean')
hc_players <- hclust(dist_players, method = "complete")

# Create a dendrogram object from the hclust variable
dend_players <- as.dendrogram(___)

# Plot the dendrogram


# Color branches by cluster formed from the cut at a height of 20 & plot
dend_20 <- color_branches(___, h = ___)

# Plot the dendrogram with clusters colored below height 20


# Color branches by cluster formed from the cut at a height of 40 & plot
dend_40 <- ___

# Plot the dendrogram with clusters colored below height 40

코드 편집 및 실행