R语言鸢尾花数据集层次聚类分析与可视化
这段代码使用R语言中的层次聚类算法(hierarchical clustering)来对鸢尾花数据集(iris)进行聚类分析,并绘制了不同特征子集的树状图。具体来说,代码分别使用了前两个特征、前三个特征、前四个特征以及每个特征子集中的两个特征来进行聚类分析。最后,使用plot函数将每个聚类结果绘制成树状图,以便于可视化和分析。
代码如下:
hc5 <- hclust(dist(iris_new[,1:2])) hc6 <- hclust(dist(iris_new[,1:3])) hc7 <- hclust(dist(iris_new[,1:4])) hc8 <- hclust(dist(iris_new[,2:3])) hc9 <- hclust(dist(iris_new[,2:4])) hc10 <- hclust(dist(iris_new[,3:4])) plot(hc5) plot(hc6) plot(hc7) plot(hc8) plot(hc9) plot(hc10)
原文地址: https://www.cveoy.top/t/topic/oyOY 著作权归作者所有。请勿转载和采集!