层次聚类算法又称为树聚类算法,它根据数据之间的距离,透过一种层次架构方式,反复将数据进行聚合,创建一个层次以分解给定的数据集。 常用于一维数据的自动分组
层次聚类方法 hclust(dist)
距离矩阵的计算方式 dist(data)
层次聚类的代码实现:
pColumns <- c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width');
data <- iris[ , pColumns]
data.e <- dist(data)
data.m <- as.matrix(data.e)
model <- hclust(data.e)
plot(model)
result <- cutree(model, k=3)
table(iris[, 5], result)
result
1 2 3
setosa 50 0 0
versicolor 0 23 27
virginica 0 49 1
我们可以看到,层次聚类对这份数据的聚类得到的结果并不是太好!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有