A4.3.5 · Machine learning approaches (HL only)
A4.3.5 · 机器学习方法(仅 HL)
Association Rule Learning
关联规则学习
A hardware store notices that customers who buy paint very often buy a roller in the same visit. Nobody programmed that rule in; association rule learning found it by counting what actually turns up together across thousands of transactions.
一家五金店注意到,买油漆的顾客常常在同一次购物中也买了滚筒刷。没有人把这条规则写进程序;关联规则学习是通过统计成千上万笔交易中实际一起出现的东西发现它的。
Like clustering, this is unsupervised: the transaction data carries no label saying which items "belong" together. The algorithm only counts co-occurrence.
和聚类一样,这也是无监督的:交易数据里没有标签说明哪些商品"应该"放在一起。算法只是统计它们同时出现的次数。
Explainer
讲解
Finding what goes together
找出哪些东西常在一起
Association rule learning finds rules of the form "if a transaction contains itemset A, it is also likely to contain itemset B", by counting how often items co-occur across a large set of transactions. It is not limited to shopping baskets: the same idea uncovers patterns in fraud data or website clicks.
关联规则学习通过统计大量交易中商品共同出现的频率,找出形如"如果一笔交易包含商品集 A,那它也很可能包含商品集 B"这样的规则。它不局限于购物篮:同样的思路也能在欺诈数据或网站点击中发现规律。
Explainer
讲解
Support, confidence, lift
支持度、置信度、提升度
| Metric | What it measures | Formula |
|---|---|---|
| Support | How often an itemset appears at all, across every transaction | transactions containing the itemset ÷ all transactions |
| Confidence | For a rule A → B, how reliably B appears when A does | support(A and B) ÷ support(A) |
| Lift | Whether A and B occur together more than chance alone would predict | confidence(A → B) ÷ support(B) |
| 指标 | 它衡量什么 | 公式 |
|---|---|---|
| 支持度 | 一个商品集在所有交易中出现的频率 | 包含该商品集的交易数 ÷ 全部交易数 |
| 置信度 | 对规则 A → B,当 A 出现时 B 出现的可靠程度 | support(A 和 B) ÷ support(A) |
| 提升度 | A 和 B 一起出现的频率是否高于纯属巧合的预期 | confidence(A → B) ÷ support(B) |
A lift above 1 means the two items appear together more than random chance would suggest, so the rule is worth acting on. A lift of exactly 1 means they are statistically independent; buying A tells you nothing about B.
提升度大于 1 表示这两件商品一起出现的频率高于随机巧合所预期的,所以这条规则值得采纳。提升度恰好等于 1 表示两者在统计上相互独立;买了 A 完全不能说明关于 B 的任何事。
Explore
探索
Rules from a hardware store
五金店的规则
20 transactions from a hardware store, simplified to just four items. Click a rule to see its support, confidence and lift worked out from the basket counts below.
来自一家五金店的 20 笔交易,简化到只有四种商品。点击一条规则,看看它的支持度、置信度和提升度是如何从下面的购物篮计数中算出来的。
Check your understanding
检验你的理解
Support(paint) = 0.50 and support(paint and roller) = 0.35. What is confidence(paint → roller)?
Support(油漆) = 0.50,support(油漆和滚筒刷) = 0.35。confidence(油漆 → 滚筒刷)是多少?
Common mistake
常见错误
RecurringTreating confidence as if it already accounts for how common the recommended item is on its own. A rule can have high confidence purely because item B is popular with everyone, paint-buyer or not, not because A and B are genuinely linked. That is exactly what lift checks: a lift near 1 means the "association" is really just B's general popularity showing through.
反复出现把置信度当成已经考虑了被推荐商品本身有多常见。一条规则可能置信度很高,纯粹是因为商品 B 本来就很受欢迎,不管顾客买没买油漆,而不是因为 A 和 B 之间真的有关联。这正是提升度要检查的:提升度接近 1 就说明这个"关联"其实只是 B 本身的高人气在起作用。
Wrong: "The rule {paint} → {roller} has 70% confidence, so paint strongly causes people to buy a roller."
错误: "规则 {油漆} → {滚筒刷} 的置信度是 70%,所以油漆强烈地导致人们购买滚筒刷。"
Right: "The rule has 70% confidence, but confidence alone does not rule out that rollers are just generally popular. Checking the lift confirms whether paint buyers choose a roller more often than a random customer would, which is what actually supports stocking them together."
正确: "这条规则的置信度是 70%,但仅凭置信度无法排除滚筒刷本身就很受欢迎这种可能。检查提升度能确认买油漆的顾客选择滚筒刷的频率是否真的高于随机顾客,而这才是把两者摆在一起销售的真正依据。"
Revision questions
复习题
Specimen-paper style. Write an answer, then reveal the marking points and mark yourself.
采用样卷风格。写下答案,然后展开评分要点给自己打分。
[2]Define the term support as used in association rule learning.
[2]在关联规则学习的语境下定义支持度。
Marking points
评分要点
- Support measures how often an itemset appears across all transactions.
- Calculated as the proportion of transactions that contain it.
- 支持度衡量一个商品集在所有交易中出现的频率。
- 计算方法是包含它的交易所占的比例。
[4]Support(paint) = 0.50, support(masking tape) = 0.30, support(paint and masking tape) = 0.15. Calculate confidence(paint → masking tape) and lift(paint → masking tape).
[4]support(油漆) = 0.50,support(遮蔽胶带) = 0.30,support(油漆和遮蔽胶带) = 0.15。计算 confidence(油漆 → 遮蔽胶带) 和 lift(油漆 → 遮蔽胶带)。
Marking points
评分要点
- Confidence = 0.15 / 0.50 = 0.30.
- Lift = 0.30 / 0.30 = 1.0.
- Lift of 1.0 means paint and masking tape are statistically independent, buying paint does not make masking tape more likely.
- 置信度 = 0.15 / 0.50 = 0.30。
- 提升度 = 0.30 / 0.30 = 1.0。
- 提升度为 1.0 说明油漆和遮蔽胶带在统计上是独立的,买油漆并不会让买遮蔽胶带更有可能。
[3]Describe one real-world application of association rule learning other than a shopping basket.
[3]描述除购物篮以外,关联规则学习的一个现实应用。
Marking points
评分要点
- Named domain, e.g. spotting fraudulent bank transactions, or working out which pages tend to be clicked together on a website.
- Itemset/attributes named for that domain (e.g. transaction type and location for fraud).
- What the rule reveals and how it is used (e.g. flag an unusual combination for review).
- 指出一个具体领域,例如金融交易中的欺诈检测,或网站上的用户行为分析。
- 为该领域指出商品集 / 属性(例如欺诈检测中的交易类型和地点)。
- 说明规则揭示了什么、如何被使用(例如标记异常组合以供审查)。
[3]Explain why a rule can have high confidence without being a genuinely useful association.
[3]解释为什么一条规则可能置信度很高,却不是一个真正有用的关联。
Marking points
评分要点
- Confidence only measures how often B appears when A does, not how common B is overall.
- If B is popular with nearly every customer regardless of A, confidence(A → B) will be high anyway.
- Lift corrects for this by comparing against B's overall support; a lift near 1 shows the rule adds little real information.
- 置信度只衡量当 A 出现时 B 出现的频率,而不是 B 整体有多常见。
- 如果 B 本身几乎对所有顾客都很受欢迎,不管有没有 A,confidence(A → B) 依然会很高。
- 提升度通过对照 B 的整体支持度来修正这一点;提升度接近 1 说明这条规则几乎没有提供真实信息。
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.5, and every other IB CS 2027 statement.
免费账户:解锁 A4.3.5 以及所有其他 IB CS 2027 考纲陈述的每一道复习题,并同步你的学习进度。