第7章 聚类分析
文章会用到的数据请在这个网址下下载多元统计分析及R语言建模(第五版)数据
练习题
1)下面给出5个元素两两之间的距离,利用最短距离法、最长距离法和类平均法做出5个元素的谱系聚类,画谱系图并做出比较。
x1 <- c(0,4,6,1,6)
x2 <- c(4,0,9,7,3)
x3 <- c(6,9,0,10,5)
x4 <- c(1,7,10,0,8)
x5 <- c(6,3,5,8,0)
x <- rbind(x1,x2,x3,x4,x5)
y <- as.dist(x)
y
最短距离法
hc = hclust(y,"single")
hc
names(hc)
data.frame(hc $ merge,hc $ height)
plot(hc)
最长距离法
hc = hclust(y)
hc
names(hc)
data.frame(hc $ merge,hc $ height)
plot(hc)
类平均距离法
hc = hclust(y,"average")
hc
names(hc)
data.frame(hc $ merge,hc $ height)
plot(