M7-083M7: Retrieval, Ranking & RecSysOffline Evaluation & OPEEasy
⚡Flashcard Drill➔Mastery:

Explain Why Offline Evaluation Cannot Naively Use Historical Logged Data to Evaluate New Policies

🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
Next: M7-084 →
📐 Mathematical Definition
history∼πold;Eπnew≠1n∑ri (biased)\text{history}\sim\pi_{\text{old}};\qquad \mathbb{E}_{\pi_{\text{new}}}\ne\frac1n\sum r_i\ (\text{biased})
⚡ One-Sentence Core Answer
Historical interaction logs reflect biased observations generated by a past logging policy; naively averaging historical rewards evaluates the old policy rather than the candidate policy, failing to observe how users would respond to novel recommendations.

📌 Key Takeaways

  • •
    Counterfactual unobservability: We only observe user feedback for items the old policy chose to display; user response to items the new policy would choose remains unobserved.
  • •
    Selection bias & logged distribution shift: P(Logged | x) reflects the historical algorithm's biases, not the true global relevance distribution.
  • •
    The offline evaluation imperative: Demands Off-Policy Evaluation (OPE) frameworks—such as Inverse Propensity Scoring (IPS) and Doubly Robust estimators—to compute unbiased policy values.

📐 Mathematical Derivations

Mathematical & Counterfactual Formulation: The Offline Policy Evaluation Gap.

(1) The Logged Bandit Feedback Problem:
Let user/context be x∼P(x)x \sim P(x), item action be a∈Aa \in \mathcal{A}, and reward be r(x,a)r(x, a).
Historical logged dataset D={(xi,ai,ri,pi)}i=1N\mathcal{D} = \{(x_i, a_i, r_i, p_i)\}_{i=1}^N was collected under logging policy $\pi_0$:
ai∼π0(a∣xi),pi=π0(ai∣xi)a_i \sim \pi_0(a \mid x_i), \quad p_i = \pi_0(a_i \mid x_i)ri is observed ONLY for chosen action air_i \text{ is observed ONLY for chosen action } a_i
We want to evaluate the expected performance of a novel candidate policy $\pi_1$:
V(π1)=Ex∼P(x),a∼π1(a∣x)[r(x,a)]V(\pi_1) = \mathbb{E}_{x \sim P(x), a \sim \pi_1(a \mid x)} [r(x, a)]

(2) Why Direct Empirical Averaging Fails (Naive Evaluation):
Suppose we filter historical logs where the old action matches the new action (ai=π1(xi)a_i = \pi_1(x_i)) and compute the average reward:
V^naive(π1)=∑i=1Nri⋅I(ai=π1(xi))∑i=1NI(ai=π1(xi))\hat{V}_{\text{naive}}(\pi_1) = \frac{\sum_{i=1}^N r_i \cdot \mathbb{I}(a_i = \pi_1(x_i))}{\sum_{i=1}^N \mathbb{I}(a_i = \pi_1(x_i))}
Mathematical Failure: This estimator is heavily biased because the condition ai=π1(xi)a_i = \pi_1(x_i) is conditioned on the old policy choosing aia_i. Actions that π0\pi_0 chose frequently are over-represented; actions π0\pi_0 rarely explored are under-represented or have zero samples.

(3) The Common Support Condition (Positivity):
Unbiased counterfactual estimation is mathematically possible if and only if the logging policy has non-zero probability for every action the new policy might take:
∀x,a:π1(a∣x)>0  ⟹  π0(a∣x)>0\forall x, a: \quad \pi_1(a \mid x) > 0 \implies \pi_0(a \mid x) > 0
If π0\pi_0 strictly never displayed action a∗a^*, historical data contains zero information regarding how users respond to a∗a^*.

🏭 Production Trade-offs

In-Depth Analysis & Engineering Trade-offs: ① The necessity of exploration traffic for offline evaluation—if production systems run deterministic greedy policies (π0(a)∈{0,1}\pi_0(a) \in \{0, 1\}), the positivity condition is violated for 99% of actions, making offline policy evaluation mathematically impossible; reserving 2%–5% of production traffic for randomized exploration logging enables offline counterfactual evaluation. ② The Direct Method (Model-based) vs. Inverse Propensity Scoring (Importance Sampling)—Direct Method trains a regression model r^(x,a)\hat{r}(x, a) and predicts rewards for π1\pi_1; it has low variance but suffers high bias if the reward model is misspecified. IPS is strictly unbiased but suffers high variance. ③ Logging propensity scores ($p_i$) at inference time—to evaluate policies offline using IPS, production systems must log the exact probability pi=π0(ai∣xi)p_i = \pi_0(a_i \mid x_i) into Kafka alongside the interaction event; reconstructing propensity scores retrospectively is impossible. ④ Position bias confounding—in search ranking, actions are slates of items; a relevant item may have received zero clicks because π0\pi_0 placed it at rank 20; counterfactual models must account for position propensities alongside item selection propensities. ⑤ Offline replay testing vs. Full A/B testing—unbiased offline policy evaluation acts as a rigorous gatekeeper, eliminating 70% of candidate models before spending cloud budget on live A/B tests. ⑥ Interview takeaway—formalize counterfactual unobservability (rr observed only for π0(a)\pi_0(a)), prove why naive averaging is biased, state the Common Support condition π1>0  ⟹  π0>0\pi_1 > 0 \implies \pi_0 > 0, and motivate Off-Policy Evaluation (OPE).
⚠️ Common Interview Pitfalls
  • ✕
    Evaluating a new ranking policy by filtering historical click logs for matching items and calculating empirical click rates, committing severe selection bias.
  • ✕
    Deploying deterministic greedy logging policies that assign zero probability to un-ranked items, permanently preventing counterfactual offline evaluation.
  • ✕
    Failing to log the execution propensity p_i = pi_0(a_i | x_i) at online inference time, rendering historical logs useless for importance sampling.
🎯 Interviewer Follow-up Inquiries
  • ?
    Why is the Common Support (Positivity) assumption mandatory for unbiased Off-Policy Evaluation?
  • ?
    What architectural logging patterns capture exact action propensities p_i without impacting online query latency?
  • ?
    How does the Direct Method (DM) compare against Inverse Propensity Scoring (IPS) in terms of the bias-variance trade-off?
⚡
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➔
📚

Associated Knowledge Base Guides & Mindmaps

← PreviousM7-082: Explain Customer Lifetime Value (LTV) Modeling versus Short-Term Metric Trade-Offs📋 Back to BankNext →M7-084: Write the Inverse Propensity Scoring (IPS) Estimator and Explain Its High Variance and Mitigation Strategies
中文速览与面试要点

解释离线评估为何不能直接用历史数据评估新策略

历史数据由'旧策略'产生(有偏),故'新策略在历史数据上的表现'不等于'新策略上线后的表现'。

核心要点

  • 数学机理: 为什么不能直接用历史数据 ——(1) 历史数据是'旧策略'产生的 ——历史日志记录了'旧策略 π_old 推荐了什么、用户如何反应'; 关键 —— 用户只对'被展示的'物品有反馈 ;未展示的物品 没有数据 ('反事实'未知)。(2) 直接平均的偏置 ——若用'历史数据的平均奖励'评估新策略 π_new:(a) 这实际上是'评估 π_old 的表现'(因为数据由 π_old 产生);(b) 新策略若'推荐了历史上没被展示的物品' → 那些物品没有数据 → 无法评估;(c) 偏差来源 ——'选择偏差'(旧策略的选择)+ '展示偏差'(只有被展示的有反馈)。(3) 支持集不匹配(support mismatch) ——(a) 新策略 π_new 可能给'π_old 从未展示的物品'很高概率 → 但这些物品 在历史数据中不存在 ;(b) 故'无法从历史数据估计新策略的表现'(无数据);(c) 这是 OPE 的 根本困难 。(4) '离线 NDCG'也有偏 ——(a) 用'历史点击'作为'相关性标签'评估新策略的排序;但 点击受位置影响 (位置偏置)→ '离线 NDCG'衡量的是'新策略与旧策略的一致性'(而非'真实相关性');(b) 故'离线 NDCG 高'可能只是'新策略像旧策略'。 正确的做法(OPE) ——(1) 逆倾向加权(IPS) ——用'1/倾向'加权历史数据,使其'模拟'随机策略的数据(见 IPS 题);(2) 直接方法(DM) ——用模型预测'新策略下的奖励'(依赖模型准确性);(3) 双稳健(DR) ——结合 DM 与 IPS(见 DR 题);(4) 随机化数据 ——用'随机策略'收集数据(无偏,但损害体验);(5) 在线 A/B ——最终验证。 前提假设(OPE 的三大假设) ——(a) 无混淆(unconfoundedness) ——'展示'只依赖'可观测的特征'(无隐藏混淆);(b) 正性/重叠(positivity/overlap) ——新策略会选的物品在历史中'有非零的展示概率'(否则无法估计);(c) SUTVA(稳定单位处理值假设) ——一个物品的反馈不受其他物品影响(无干扰); 注意 ——(b) 是最易违反的(新策略选的新物品从未展示)。 与其他问题的关系 ——(a) 与'位置偏置'(同一问题);(b) 与'离线-在线不一致'(LTR 题);(c) 与'因果推断'(OPE 是因果推断的应用)。 实践建议 ——(a) 不要直接用历史数据平均评估新策略 ;(b) 用 IPS/DR (配权重截断);(c) 保留随机化数据 (金标准);(d) 检查'支持集重叠' (新策略选的物品在历史中有多少概率被展示);(e) 离线只做粗筛、A/B 定胜负 。 度量 ——(a) OPE 估计的偏差(vs 在线 A/B);(b) 支持集重叠度;(c) 估计的方差。
  • 深度剖析与工程权衡:① '历史数据由旧策略产生'是根本问题 ——故'直接平均 = 评估旧策略';面试中能指出这一点是深度理解的标志。② '支持集不匹配'是 OPE 的根本困难 ——新策略选的新物品无数据;故'正性假设'最易违反。③ '离线 NDCG 也有偏' ——它衡量'与旧策略的一致性';这是易被忽视的陷阱。④ '随机化数据是金标准' ——小流量随机可提供无偏数据;代价是体验损失。⑤ '三大假设'需明确 ——无混淆/正性/SUTVA;违反则 OPE 失效。⑥ 面试要点 ——被问'为什么不能用历史数据评估新策略',应给出' 历史数据由旧策略产生(选择偏差)+ 支持集不匹配 + 离线 NDCG 也有偏 + 正确做法(IPS/DR/随机化/A-B)+ 三大假设 ';能指出'离线 NDCG 衡量的是与旧策略的一致性'是深度理解的标志。
  • 历史数据是'旧策略'选择的(有偏采样)
  • 直接平均历史数据 = 评估旧策略(而非新策略)
  • 新策略可能'推荐历史上没出现过的物品'(无数据)

常见陷阱

  • 直接用历史数据的平均奖励评估新策略
  • 忽略'正性假设'(新策略选的物品无历史数据)