![23020d38a9d448f9c2d1fe8749d23ab0.gif](https://img-blog.csdnimg.cn/img_convert/23020d38a9d448f9c2d1fe8749d23ab0.gif)
![ef3c46a0bf30a1a7495a99aacd9d01c1.png](https://img-blog.csdnimg.cn/img_convert/ef3c46a0bf30a1a7495a99aacd9d01c1.png)
![07f9bdf2411c2dc30219d9522adb07e3.png](https://img-blog.csdnimg.cn/img_convert/07f9bdf2411c2dc30219d9522adb07e3.png)
![1000e619b18ad37afb31adc6daf7298d.png](https://img-blog.csdnimg.cn/img_convert/1000e619b18ad37afb31adc6daf7298d.png)
![1fecdcb251e9c599f66511ba0e8d0a45.png](https://img-blog.csdnimg.cn/img_convert/1fecdcb251e9c599f66511ba0e8d0a45.png)
![1000e619b18ad37afb31adc6daf7298d.png](https://img-blog.csdnimg.cn/img_convert/1000e619b18ad37afb31adc6daf7298d.png)
![1fecdcb251e9c599f66511ba0e8d0a45.png](https://img-blog.csdnimg.cn/img_convert/1fecdcb251e9c599f66511ba0e8d0a45.png)
本节需要用到的 R 包:
# 加载包
library(dplyr) # 数据预处理
library(ggplot2) # 数据可视化
library(cluster) # 实现聚类算法
library(factoextra) # 聚类结果可视化
构建测试数据集(数据来自 R 包 AmesHousing
):
# 数据预处理
ames_scale %
select_if(is.numeric) %>% # 选择数据类型为数字
select(-Sale_Price) %>% # 去除特定的数据
mutate_all(as.double) %>% # 强制转换类型
scale() # 中心化标准化数据
层次聚类算法
层次聚类算法可以分成两种:
1. 聚集聚类(Agglomerative clustering),通常叫 AGNES,理解成从个体到整体的聚类方式;
2. 分裂层次聚类(Divisive h