開始使用免費開始

階層式分群:職業樹狀圖

在前一個練習中,你已經知道 oes 資料不需任何前處理就能用於階層式分群。本題要你根據各職業的年度平均薪資建立樹狀圖(dendrogram),並以 100,000 的高度提出分群建議。

本練習屬於課程

R 的叢集分析

檢視課程

練習說明

  • 計算各職業之間的歐氏距離,並將結果存成 dist_oes
  • average 連結法進行階層式分群,並將結果存成 hc_oes
  • 使用 as.dendrogram(),把你的 hclust 結果轉成樹狀圖物件 dend_oes
  • 繪製該樹狀圖。
  • 使用 color_branches() 函式,依切割高度 100,000 產生上色的新版樹狀圖並繪製出來。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Calculate Euclidean distance between the occupations
dist_oes <- dist(___, method = ___)

# Generate an average linkage analysis 
hc_oes <- hclust(___, method = ___)

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

# Plot the dendrogram
plot(___)

# Color branches by cluster formed from the cut at a height of 100000
dend_colored <- color_branches(___, h = ___)

# Plot the colored dendrogram
plot(___)
編輯並執行程式碼