选择簇的数量

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)

  • 用于解读层次聚类的树状结构

绘制了五个观测与树状图

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 中的无监督学习

Ayo berlatih!

R 中的无监督学习

Preparing Video For Download...