M6-004Hard从零实现统计 · Implement from scratch

手写 CUPED 调整,并验证方差缩减比例。

Implement CUPED adjustment and verify the variance reduction.
💡 考场高分一句话答案:

用实验前指标 x 作协变量,θ=Cov(y,x)/Var(x),y_adj=y−θ(x−x̄),报告 1−ρ² 作为理论缩减。

Use the pre-period metric x as covariate, theta = Cov(y,x)/Var(x), adjust y, then report the theoretical reduction 1−rho squared against the observed variance ratio.

🧭 Playbook 核心提示 / Actionable Calibration:

注意 np.cov(y, x) 返回 2×2 矩阵,[0,1] 是 Cov(y,x)。若 x 与 y 量纲差异大,数值上仍稳定,但建议标准化后再算以便解释 θ。

📌 核心考察要点 (Key Points)

  • θ 的估计:用全样本估(含两组),不能用处理组单独估
  • 验证:比较调整前后的 Var(y) 与 1−ρ²
  • 陷阱:x 必须是随机化前的;若 x 含处理效应会破坏无偏性
  • 进阶:用交叉拟合 + ML 模型估 E[y|x] 得到更高 ρ
  • Estimate theta on the full sample, not within one arm
  • Verify: compare Var(y) before and after against $1-\rho^2$
  • Trap: x must be measured before randomisation or it absorbs the treatment effect
  • Extension: cross-fitting plus an ML model for E[y|x] to reach a higher rho

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

  • θ 用处理组单独估会有什么后果?
  • 如何用交叉拟合避免过拟合?

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

零打字负担,以大厂考官真实困境切入,通过点选直觉选项暴露思维盲区,手把手推导 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➔