Inferensys

Glossary

Counterfactual Evaluation

A statistical method for estimating the performance of a new policy using historical data collected under a different logging policy, without deploying the new policy live.
Data scientist reviewing AI evaluation metrics on dashboard, comparison charts visible, casual WeWork analytics setup.
OFF-POLICY VALIDATION

What is Counterfactual Evaluation?

A statistical method for estimating the performance of a new policy using historical data collected under a different logging policy, without deploying the new policy live.

Counterfactual evaluation is an off-policy evaluation technique that estimates how a new decision-making policy would perform if deployed, using only historical data generated by a different, previously deployed logging policy. It answers the "what if" question by correcting for the selection bias inherent in logged data, where we only observe outcomes for actions the old policy chose, not the ones the new policy might have taken. This is critical for safely validating models like contextual multi-armed bandits before exposing them to live traffic.

The core mechanism relies on importance sampling estimators, such as the Inverse Propensity Scoring (IPS) estimator, which re-weights observed rewards by the ratio of the target policy's probability to the logging policy's probability for a given action. More advanced techniques like the Doubly Robust estimator combine IPS with a direct reward model to reduce variance and maintain unbiasedness even if one component is misspecified. This provides a principled alternative to risky online A/B tests for high-stakes personalization.

OFF-POLICY VALIDATION

Key Characteristics of Counterfactual Evaluation

Counterfactual evaluation is a statistical methodology for estimating the performance of a new target policy using only historical data collected by a different logging policy. It answers the critical question: 'How well would this new model have performed without ever deploying it live?'

01

The Fundamental Problem of Causal Inference

Counterfactual evaluation addresses the core challenge that we can only observe the outcome of the action that was taken, not the outcomes of actions that were not taken. The logged data contains the factual outcome for the chosen action, but the counterfactual outcomes for all other possible actions remain unobserved. This missing data problem is the central obstacle that off-policy estimators must overcome to provide unbiased performance estimates.

02

Inverse Propensity Scoring (IPS)

IPS is the foundational off-policy estimator that corrects for selection bias by re-weighting each observed reward by the inverse of the probability that the logging policy chose that action. The core formula is:

  • Estimator: ( V_{IPS} = \frac{1}{N} \sum_{i=1}^{N} \frac{\pi_e(a_i|x_i)}{\pi_b(a_i|x_i)} r_i )
  • Key Requirement: The logging policy (\pi_b) must have a non-zero probability of selecting any action the target policy (\pi_e) might select (common support)
  • Variance Challenge: IPS can suffer from high variance when the logging and target policies diverge significantly, leading to large importance weights
03

Doubly Robust Estimation

The doubly robust estimator combines IPS with a direct method reward model to provide a more reliable estimate. It remains unbiased if either the propensity model or the reward model is correctly specified, providing a crucial safety net:

  • Direct Method Component: Learns a model (\hat{r}(x, a)) to predict the reward for any context-action pair
  • Correction Term: Adds an IPS-weighted correction for the residuals of the direct method predictions
  • Practical Advantage: In real-world applications where perfect propensity or reward models are rare, the doubly robust estimator often exhibits significantly lower variance than pure IPS
04

The Common Support Assumption

For off-policy evaluation to be valid, the logging policy must have explored the action space sufficiently. The common support or overlap condition requires that for any context where the target policy assigns a non-zero probability to an action, the logging policy must also have a non-zero probability of selecting that action:

  • Violation Consequence: If the target policy selects actions the logging policy never tried, the estimate becomes biased and unreliable
  • Detection: Inspect the distribution of propensity scores and importance weights for extreme values
  • Mitigation: Clip importance weights or use self-normalized estimators to trade some bias for reduced variance
05

Off-Policy vs. On-Policy Evaluation

Understanding the distinction between evaluation paradigms is critical for safe model deployment:

  • On-Policy Evaluation: The model being evaluated is the same model that collected the data. Requires no correction but demands live deployment
  • Off-Policy Evaluation: The target model differs from the data-collecting logging model. Enables safe, pre-deployment assessment but requires statistical correction
  • A/B Testing: The gold-standard on-policy method that randomly assigns users to control and treatment groups, directly measuring causal impact without modeling assumptions
  • Counterfactual Advantage: Allows rapid iteration on model candidates without the business risk or time cost of live experiments
06

Variance Reduction Techniques

High variance in off-policy estimates can render them useless for decision-making. Key techniques to stabilize estimates include:

  • Weight Clipping: Capping importance weights at a maximum threshold to prevent any single sample from dominating the estimate
  • Self-Normalized IPS: Dividing by the sum of importance weights rather than the sample size N, trading a small amount of bias for dramatic variance reduction
  • Control Variates: Subtracting a baseline function from the reward that has a known expected value under the target policy, reducing variance without introducing bias
  • Bootstrapped Confidence Intervals: Resampling the logged data to construct empirical confidence intervals around the point estimate
COUNTERFACTUAL EVALUATION

Frequently Asked Questions

Clear, technically precise answers to the most common questions about validating new personalization policies using only historical log data, without risking live user experience.

Counterfactual evaluation is a statistical method for estimating the performance of a new policy using historical data collected under a different logging policy, without deploying the new policy live. It works by answering the counterfactual question: "What would have happened if we had used policy B instead of policy A?" The core mechanism involves re-weighting observed outcomes by the ratio of the target policy's action probability to the logging policy's action probability, a technique known as Inverse Propensity Scoring (IPS). This corrects for the selection bias inherent in logged data, where we only observe outcomes for actions the logging policy chose. The method assumes the logging policy has a non-zero probability of selecting any action the target policy might choose, a condition called common support or overlap. Counterfactual evaluation is the foundation of safe, offline model validation for recommender systems and contextual bandits.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.