Overview

5 Counterfactual evaluations

Counterfactual evaluations provide a way to ask “what if” questions about AI decisions using historical production data rather than live experimentation. The chapter begins by connecting this idea to causal inference, which focuses on cause and effect instead of simple correlation. It explains that these methods estimate how a different model, ranking policy, recommendation strategy, or agent action might have performed, but only as an estimate built from observed logs, propensities, outcomes, and assumptions.

To make counterfactual evaluation work, the chapter emphasizes the need for rich, intentional logging and a clear evaluation structure. At minimum, systems should record the decision context, the action taken, the probability of that action, the candidate set, the model or policy version, and the resulting outcome. With that foundation, methods such as inverse propensity weighting, off-policy evaluation, and policy value estimation can compare a candidate policy against the logged baseline. The text also highlights that usefulness depends on overlap between policies, accurate propensities, enough contextual detail, and stable effective sample size.

The chapter closes by stressing both the strengths and the limits of this approach. Counterfactual evaluations are fast, low-risk, and useful when A/B tests are impractical, especially for rare or high-stakes scenarios, but they are only as trustworthy as the data and assumptions behind them. Common failures include incomplete logging, biased probabilities, poor overlap, and missing context. The discussion extends these ideas to search, recommendation, LLM, and agentic systems, where careful engineering is needed to balance logging quality, storage cost, latency, and privacy while preserving enough evidence to support reliable offline judgment.

An input-output framework for counterfactual evaluations, illustrating how logged data feeds into processes like off-policy evaluation to generate actionable metrics such as policy value, incremental action value, and uplift.
illustrates a simplified counterfactual evaluation workflow. Logged interaction data is reweighted using an off-policy correction method, such as inverse propensity weighting, to estimate the value of a candidate policy. That estimate is then compared with a baseline policy. The workflow assumes correct logging, sufficient overlap between the logged and candidate policies, and enough contextual information to support meaningful comparison.
illustrates an example of policy value evaluation in a movie recommendation system, illustrating how logged data, such as recommended movies, alternative options, and contextual details, is processed using techniques like inverse propensity weighting to produce actionable metrics such as engagement and retention.

Summary

  • Counterfactual evaluations help estimate what might have happened if a different model, ranking policy, recommendation policy, or decision strategy had been used.
  • These evaluations are useful, but they are estimates under assumptions, not perfect replays of an alternate reality.
  • Causal inference is about understanding cause and effect. Counterfactual thinking is one way to reason about the outcomes of decisions we did not actually take.
  • Counterfactual logging captures the decision as it looked at the time: the context, candidate set, selected action, action probabilities or scores, policy version, and observed outcome.
  • Policy value is the expected performance of a policy. Off-policy evaluation is the family of methods used to estimate that value from data collected by a different policy.
  • Inverse Propensity Weighting reweights logged outcomes based on how likely the new policy would have been to take the logged action compared to the original policy.
  • IPW and related methods require accurate propensities, enough overlap between the logged and new policies, and careful checks for unstable weights.
  • Effective sample size, confidence intervals, segment-level checks, and weight distributions help determine whether a counterfactual estimate is trustworthy.
  • Good logging architecture balances evaluation needs with latency, storage cost, privacy, governance, and long-term maintainability.

FAQ

What is causal inference, and why does it matter for counterfactual evaluations?Causal inference is the process of figuring out what caused what—estimating cause-and-effect relationships rather than just correlations. It matters for counterfactual evaluations because it helps you estimate what would have happened if a different decision had been made, which is the core “what if” question these evaluations try to answer.
What is a counterfactual evaluation in AI?A counterfactual evaluation estimates how a model, ranking policy, recommendation policy, or decision strategy might have performed under a different action than the one actually taken. It uses logged production data, action probabilities, observed outcomes, and assumptions to simulate alternate outcomes without running a live experiment.
What data do I need to perform a counterfactual evaluation?You typically need the decision context at the time of action, the action taken, the probability of taking that action, the candidate set considered, the policy or model version, and the observed outcome. Rich and accurate logs are essential because counterfactual methods rely on historical data to estimate unobserved outcomes.
Why is overlap between the logged policy and the new policy so important?Overlap means the logged policy sometimes took actions that the new policy would take too. Without overlap, there is little historical evidence to support the counterfactual estimate, so the result becomes highly assumption-heavy, unstable, or unreliable.
What is inverse propensity weighting (IPW) used for?Inverse propensity weighting is a common method for correcting bias in counterfactual evaluations. It reweights logged outcomes based on how likely the new policy would have been to take the observed action compared with the old policy, helping estimate how the candidate policy might have performed.
What is policy value in counterfactual evaluation?Policy value is the expected performance of a policy if it were deployed. In practice, it is the quantity you want to estimate offline, such as expected click-through rate, watch time, purchase rate, task success, or retention impact.
How is off-policy evaluation different from policy value?Policy value is the metric you want to estimate, while off-policy evaluation is the method used to estimate that value using data collected from another policy. Off-policy evaluation lets you compare a candidate policy to the current one without exposing users to the new policy first.
What are the main strengths of counterfactual evaluations?They are fast, relatively low-risk, and cost-effective because they reuse existing logged data instead of requiring an online experiment. They are especially useful when A/B tests are impractical, such as for rare events, high-risk changes, or situations where user impact should be minimized.
What are the biggest limitations or pitfalls of counterfactual evaluations?The biggest pitfalls are incomplete logging, biased or inaccurate propensity scores, poor overlap between old and new policies, and missing contextual variables. These issues can make estimates unstable or misleading, so counterfactual results should be treated as estimates, not proof.
What are the key logging best practices for counterfactual evaluations?Log intentionally: capture the candidate set, selected action, action probabilities, contextual metadata, policy version, and downstream outcomes. Logging should be consistent and unbiased across actions and user groups, and it should preserve enough detail to support the specific counterfactual questions you plan to ask later.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • AI Model Evaluation ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • AI Model Evaluation ebook for free