A4.3.4 · Machine learning approaches (HL only)
A4.3.4 · 机器学习方法(仅 HL)
Clustering Techniques in Unsupervised Learning
无监督学习中的聚类技术
Nobody tells the algorithm which group a runner's race time belongs to. Clustering only looks at how similar the data points are to each other, and lets natural groups emerge on their own.
没有人告诉算法一名跑者的比赛用时属于哪一组。聚类只看数据点彼此有多相似,让自然的分组自己浮现出来。
This builds on A4.1.1's definition of unsupervised learning: the training data carries no correct-answer labels at all.
这建立在 A4.1.1 对无监督学习的定义之上:训练数据完全不带任何正确答案标签。
Explainer
讲解
Grouping without labels
不带标签地分组
Clustering groups data points so that anything sitting in the same cluster is close (usually measured as distance between feature values) to the rest of that cluster, and further away from points in every other cluster. No labelled "correct" grouping is supplied; the algorithm discovers the structure itself.
聚类把数据点分组,使同一簇内的点彼此更相似(通常以特征值之间的距离来衡量),而与其他簇里的点差异更大。没有提供带标签的"正确"分组;算法自己发现这种结构。
A gym app records each member's weekly workout count and average session length. Nobody labelled any member "casual" or "dedicated", but clustering can still find natural groupings in that data, letting the app suggest a plan that fits the group a member actually falls into.
一款健身应用记录每位会员每周的锻炼次数和平均单次时长。没有人给任何会员贴上"随意型"或"投入型"的标签,但聚类仍然能在这些数据中找到自然的分组,让应用为会员实际所属的那一组推荐合适的计划。
Explainer
讲解
Four clustering families
四种聚类家族
| Method | How it groups | Good fit / weakness |
|---|---|---|
| K-means | Assigns each point to the nearest of k centre points (centroids), then moves each centroid to the mean of its assigned points, repeating until stable | Fast, simple; assumes roughly spherical, similar-sized clusters and needs k chosen in advance |
| Hierarchical | Repeatedly merges the two closest clusters (starting from one point per cluster) into a tree, called a dendrogram | Shows structure at every scale at once; slower on large data sets |
| DBSCAN | Groups points that are densely packed together and marks isolated points as noise/outliers | Finds clusters of any shape and does not need k specified; struggles when clusters have very different densities |
| Mean shift | Repeatedly slides each candidate centre to the mean of nearby points until it settles | Works on arbitrary shapes without setting k in advance; more computation per point |
| 方法 | 如何分组 | 适合的场景 / 弱点 |
|---|---|---|
| K-均值 | 把每个点分给最近的 k 个中心点(质心)之一,然后把每个质心移到其所属点的均值位置,重复直到稳定 | 快速、简单;假定簇大致呈球形且大小相近,且需要事先选定 k |
| 层次聚类 | (从每个点各自成一簇开始)反复合并最接近的两个簇,形成一棵树,称为树状图 | 能一次性展示各种尺度下的结构;在大数据集上较慢 |
| DBSCAN | 把密集聚集在一起的点分为一组,把孤立的点标记为噪声 / 异常值 | 能找到任意形状的簇,且不需要事先指定 k;在簇的密度差异很大时表现较差 |
| 均值漂移 | 反复把每个候选中心滑动到附近点的均值位置,直到它稳定下来 | 无需事先设定 k,就能处理任意形状;每个点的计算量更大 |
Worked example
例题
K-means, step by step
逐步演示 K-均值
Nine runners plotted by pace (x) and distance run per week (y). Watch k = 2 centroids settle into two natural pace groups.
九名跑者按配速(x)和每周跑量(y)画在图上。看 k = 2 个质心如何落定为两个自然的配速分组。
The basic loop: (1) place k centroids, (2) assign every point to its nearest centroid, (3) move each centroid to the mean of its assigned points, (4) repeat 2 and 3 until no assignment changes.
基本循环:(1)放置 k 个质心,(2)把每个点分给最近的质心,(3)把每个质心移到其所属点的均值位置,(4)重复步骤 2 和 3,直到没有点再改变归属。
Check your understanding
检验你的理解
A data set has a handful of extreme outliers scattered far from any real grouping. Which clustering method handles this best, without those outliers distorting the real clusters?
一个数据集里散布着少量极端的离群点,远离任何真实的分组。哪种聚类方法能最好地处理这种情况,而不让这些离群点扭曲真正的簇?
Common mistake
常见错误
RecurringClaiming K-means "finds the natural clusters in any data set". K-means assumes clusters are roughly spherical and similar in size, because it assigns points purely by distance to a single centre point. Long, thin or unevenly sized clusters, or ones nested inside each other, defeat it. The number of clusters, k, also has to be chosen before running it; K-means cannot decide that number itself.
反复出现声称 K-均值"能在任何数据集中找到自然的簇"。K-均值假定簇大致呈球形且大小相近,因为它纯粹按到单一中心点的距离来分配点。细长的、大小悬殊的,或彼此嵌套的簇都会让它失效。簇的数量 k 也必须在运行前就选定;K-均值本身无法决定这个数字。
Wrong: "K-means clustering works on any data set and automatically works out how many groups there really are."
错误: "K-均值聚类适用于任何数据集,并且会自动算出实际有多少组。"
Right: "K-means requires k to be chosen in advance and assumes clusters are roughly spherical and similar in size, since it assigns points by distance to a centroid. It struggles with irregular shapes or very different cluster sizes; DBSCAN or hierarchical clustering suit those cases better."
正确: "K-均值需要事先选定 k,并假定簇大致呈球形且大小相近,因为它按到质心的距离来分配点。它在处理不规则形状或大小差异很大的簇时表现不佳;这些情况用 DBSCAN 或层次聚类更合适。"
Revision questions
复习题
Specimen-paper style. Write an answer, then reveal the marking points and mark yourself.
采用样卷风格。写下答案,然后展开评分要点给自己打分。
[2]State what makes clustering an unsupervised technique.
[2]说出是什么使聚类成为一种无监督技术。
Marking points
评分要点
- The training data has no labels stating the correct group for each point.
- The algorithm groups points by similarity between their feature values alone.
- 训练数据没有标签说明每个点正确所属的分组。
- 算法仅凭特征值之间的相似性来分组。
[4]Describe the four main steps of the K-means algorithm.
[4]描述 K-均值算法的四个主要步骤。
Marking points
评分要点
- Initialise k centroids (often at random positions).
- Assign each point to its nearest centroid.
- Recalculate each centroid as the mean of its assigned points.
- Repeat assignment and recalculation until the centroids stop moving / assignments stop changing.
- 初始化 k 个质心(通常是随机位置)。
- 把每个点分配给最近的质心。
- 把每个质心重新计算为其所属点的均值。
- 重复分配和重新计算,直到质心不再移动 / 分配不再变化。
[3]Describe one real-world application of clustering.
[3]描述聚类的一个现实应用。
Marking points
评分要点
- Named application, e.g. customer segmentation for marketing.
- States what the clusters represent (e.g. groups of customers with similar purchasing behaviour).
- States the business/practical benefit (e.g. targeted campaigns per segment).
- 指出一个具体应用,例如用于营销的客户细分。
- 说明簇代表什么(例如购买行为相似的客户群体)。
- 说明业务 / 实际收益(例如针对每个细分群体的定向营销)。
[3]Explain why DBSCAN does not need the number of clusters set in advance, unlike K-means.
[3]解释为什么 DBSCAN 不像 K-均值那样需要事先设定簇的数量。
Marking points
评分要点
- DBSCAN groups points based on density (how many neighbours lie within a set distance), not by assigning to a fixed count of centres.
- Clusters emerge wherever a dense region is found; the count is a result, not an input.
- K-means must assign every point to one of exactly k centroids, so k must be fixed before it runs.
- DBSCAN 根据密度(在设定距离内有多少邻居)分组,而不是分配给固定数量的中心。
- 只要发现一个密集区域,簇就会浮现出来;簇的数量是结果,不是输入。
- K-均值必须把每个点分配给恰好 k 个质心之一,所以 k 必须在运行前就固定下来。
Flashcards
记忆卡片
Active recall for this statement’s key terms.
针对本条考纲陈述关键术语的主动回忆练习。
Keep this statement’s practice with you
把这条考纲陈述的练习保存下来
Free account: save your progress and unlock every revision question for A4.3.4, and every other IB CS 2027 statement.
免费账户:解锁 A4.3.4 以及所有其他 IB CS 2027 考纲陈述的每一道复习题,并同步你的学习进度。