层次聚类:职业树
在上一个练习中,您已经了解到 oes 数据无需任何预处理即可进行层次聚类。本练习中,您将基于各职业的年度平均薪资构建一个树状图(dendrogram),并在高度为 100,000 时提出聚类方案。
本练习是课程的一部分
R 中的聚类分析
练习说明
- 计算各职业之间的欧式距离,并将结果保存为
dist_oes。 - 使用 average 连接方式运行层次聚类,并将结果保存为
hc_oes。 - 使用函数
as.dendrogram(),将hclust的结果转换为树状图对象dend_oes。 - 绘制该树状图。
- 使用
color_branches()函数,依据剪切高度 100,000 为聚类上色,创建并绘制一个新的树状图。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Calculate Euclidean distance between the occupations
dist_oes <- dist(___, method = ___)
# Generate an average linkage analysis
hc_oes <- hclust(___, method = ___)
# Create a dendrogram object from the hclust variable
dend_oes <- as.dendrogram(___)
# Plot the dendrogram
plot(___)
# Color branches by cluster formed from the cut at a height of 100000
dend_colored <- color_branches(___, h = ___)
# Plot the colored dendrogram
plot(___)