選擇叢集數量

R 的無監督式學習

Hank Roark

Senior Data Scientist at Boeing

解讀結果

# Create hierarchical cluster model: hclust.out
hclust.out <- hclust(dist(x))

# Inspect the result summary(hclust.out)
            Length Class  Mode     
merge       98     -none- numeric  
height      49     -none- numeric  
order       50     -none- numeric  
labels       0     -none- NULL     
method       1     -none- character
call         2     -none- call     
dist.method  1     -none- character
R 的無監督式學習

樹狀圖(Dendrogram)

  • 樹狀結構,用來解讀階層式分群模型。

繪出 5 筆觀測與樹狀圖

R 的無監督式學習

樹狀圖(Dendrogram)

  • 樹狀結構,用來解讀階層式分群模型。

在樹狀圖中連結兩個分群點

R 的無監督式學習

樹狀圖(Dendrogram)

  • 樹狀結構,用來解讀階層式分群模型。

在樹狀圖中連結另外兩個分群點

R 的無監督式學習

樹狀圖(Dendrogram)

  • 樹狀結構,用來解讀階層式分群模型。

在樹狀圖中連結兩個分群與一個點

R 的無監督式學習

樹狀圖(Dendrogram)

  • 樹狀結構,用來解讀階層式分群模型。

在樹狀圖中將所有分群與點合併

R 的無監督式學習

在 R 中繪製樹狀圖

# Draws a dendrogram
plot(hclust.out)

abline(h = 6, col = "red")

水平線標示在樹狀圖上想要的叢集數

R 的無監督式學習

在 R 中「切割」樹

# Cut by height h
cutree(hclust.out, h = 6)
1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3
3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 2 4 2 4 4
# Cut by number of clusters k
cutree(hclust.out, k = 2)
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2
2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1
R 的無監督式學習

一起來練習吧!

R 的無監督式學習

Preparing Video For Download...