M5-014Hard去重与关联 · Dedup & joins🔥 大厂高频出现 1 次

如何计算品类之间的关联购买(购物篮分析)?

How do you compute category affinity (market-basket analysis)?
💡 考场高分一句话答案:

自连接同一订单的品类对,统计共现次数,再用支持度/置信度/提升度衡量关联强度。

Self-join categories within the same order to count co-occurrence, then compute support, confidence and lift.

📌 核心考察要点 (Key Points)

  • 自连接:同 order_id 下不同 category 的两两组合,用 a.category < b.category 去重对称对
  • 支持度:$P(A,B)$;置信度:$P(B\mid A)$;提升度:$P(B\mid A)/P(B)$
  • 提升度才是关键:支持度高可能只是因为两个品类都很热门
  • 性能:大表自连接会爆炸,先聚合到 (order, category) 去重
  • Self-join: same order_id, different categories, with a.category < b.category to remove symmetric duplicates
  • Support: $P(A,B)$; confidence: $P(B\mid A)$; lift: $P(B\mid A)/P(B)$
  • Lift is the point: high support may just mean both categories are popular
  • Performance: large self-joins explode, so aggregate to (order, category) first

🔍 大厂面试官连环追问 (Follow-ups)

  • 提升度为 1 意味着什么?
  • 如何处理“同一品类买多件”的情况?

🎯 关联大厂考题实战训练 (1 题)

嫌字多看太累?进入苏格拉底式对话推演实验室

零打字负担,以大厂考官真实困境切入,通过点选直觉选项暴露思维盲区,手把手推导 Why。

💬 开启对话式破冰 ➔
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔