M4-006Medium假设检验 · Hypothesis testing🔥 大厂高频出现 6 次
卡方检验在 Product DS 里有哪些用途?
What is the chi-square test used for in product data science?
💡 考场高分一句话答案:
卡方拟合优度检验用于单分类变量分布校验(如 SRM 样本分流比对齐),卡方独立性检验用于两分类变量关联分析,核心是度量观测频数与理论期望频数的加权平方差。
Two main uses: checking the randomisation ratio (SRM) and testing independence in a contingency table, such as whether a segment is associated with conversion.
📌 核心考察要点 (Key Points)
- SRM:$\chi^2=\sum(O-E)^2/E$,df=组数−1,阈值用 p<0.001
- 独立性:用户分群 × 是否转化,判断分群与行为是否相关
- 前提:期望频数 ≥ 5;不满足时用 Fisher 精确检验
- 注意:卡方只说“有关联”,不说方向和强度;需配合 Cramér's V 看强度
- SRM: $\chi^2=\sum(O-E)^2/E$ with df = arms − 1; threshold p<0.001
- Independence: segment × converted, to test association
- Assumption: expected counts at least 5; otherwise use Fisher's exact test
- Limitation: chi-square says 'associated', not direction or magnitude — pair with Cramér's V
📐 第一性原理与数理推导机理
设分类变量的观测频数为 $O_{ij}$,在独立性零假设下的理论期望频数为 $E_{ij} = \frac{R_i C_j}{N}$($R_i, C_j$ 为行列表边际总计)。构造 Pearson 卡方统计量:$$\chi^2 = \sum_{i=1}^r \sum_{j=1}^c \frac{(O_{ij} - E_{ij})^2}{E_{ij}}$$根据多项分布渐近正态性质,该统计量在独立性假设下渐近服从自由度为 $(r-1)(c-1)$ 的卡方分布。
⚠️ 常见高频面试陷阱与避坑指南
- 在期望单元格频数 $< 5$ 时仍强行使用卡方检验(应使用 Yates 连续性校正或 Fisher's Exact Test)。
- 将连续指标或金额均值当作离散频数传入卡方公式,破坏多项式分布的前提假设。
🔍 大厂面试官连环追问 (Follow-ups)
- 为什么在 SRM(Sample Ratio Mismatch)检测中通常使用卡方检验而不是双比例 z 检验?
- 如果卡方检验显著(p < 0.001),说明什么?能直接证明是算法作弊吗?
🎯 关联大厂考题实战训练 (6 题)
嫌字多看太累?进入苏格拉底式对话推演实验室
零打字负担,以大厂考官真实困境切入,通过点选直觉选项暴露思维盲区,手把手推导 Why。
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.