Skip to content

Add DR and plug-in T scoring metrics for CATE model evaluation#930

Merged
jeongyoonlee merged 4 commits into
uber:masterfrom
aman-coder03:feature/cate-scoring-dr-plugin-t
Jul 7, 2026
Merged

Add DR and plug-in T scoring metrics for CATE model evaluation#930
jeongyoonlee merged 4 commits into
uber:masterfrom
aman-coder03:feature/cate-scoring-dr-plugin-t

Conversation

@aman-coder03

Copy link
Copy Markdown
Contributor

Proposed changes

this pr adds two new observed-data surrogate metrics for evaluating fitted cate models without access to true counterfactual outcomes

what's included

  • added compute_dr_pseudo_outcomes() to construct cross-fitted doubly robust (aipw) pseudo-outcomes that can be reused across different evaluation methods
  • added dr_score() to evaluate cate models using mean squared error against the dr pseudo-outcomes
  • added plug_in_t_score() to evaluate cate models against a cross-fitted plug-in t-learner cate proxy
  • reused the same pseudo-outcomes with rate_score() to avoid fitting nuisance models multiple times
  • added optional half-sample bootstrap confidence intervals and p-values, following the existing rate_score() implementation
  • added unit tests covering pseudo-outcome generation, model ranking, bootstrap inference, error handling, and compatibility with rate_score()
  • added documentation explaining the methodology and intended use of the new metrics

closes #922

Types of changes

What types of changes does your code introduce to CausalML?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc. This PR template is adopted from appium.

@jeongyoonlee jeongyoonlee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core AIPW/T-learner construction and the docs are solid, but one blocker before merge:

Both compute_dr_pseudo_outcomes and plug_in_t_score can crash on imbalanced treatment — plain KFold doesn't stratify.
Each fold fits per-arm outcome models on X[train_idx][w_train == 0] and X[train_idx][w_train == 1]. With KFold(shuffle=True) (not StratifiedKFold), a fold's training split can end up with zero units of one arm, so .fit() on the empty slice raises:

ValueError: Found array with 0 sample(s) (shape=(0, n_features)) while a minimum of 1 is required

Reproduced on rare-treatment data — which is exactly the observational setting these surrogate metrics target — at 3 treated / n=200 / 5 folds (crashes on 1 of 50 seeds):

w = np.zeros(200, int); w[rng.choice(200, 3, replace=False)] = 1
compute_dr_pseudo_outcomes(X, w, y, learner=LinearRegression(), n_folds=5, random_state=15)
# ValueError: Found array with 0 sample(s) ...

Please switch both functions to StratifiedKFold(n_splits=n_folds, shuffle=True, random_state=...) and split on the treatment vector (cv.split(X, treatment)), so every fold retains both arms. That's the standard splitter for cross-fitting AIPW / T-learner nuisances.

Non-blocking notes to follow separately.

@aman-coder03 aman-coder03 force-pushed the feature/cate-scoring-dr-plugin-t branch from 3a60762 to aa10d2a Compare July 6, 2026 12:49
@aman-coder03 aman-coder03 requested a review from jeongyoonlee July 6, 2026 13:43

@jeongyoonlee jeongyoonlee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two non-blocking nits:

  1. p_value column (_score_against_pseudo_outcome): z_stat = point / se tests H0: loss = 0, but the loss is an MSE that is ~never 0, so the p-value collapses to ≈0 for every model and conveys nothing. This is meaningful in rate_score (H0: RATE = 0 = no targeting value) but not for a loss — the informative test is a paired model-vs-model comparison. Suggest dropping the p_value column or replacing it with the paired test.

  2. metrics/__init__.py has a duplicated from .sensitivity import Sensitivity, SensitivityPlaceboTreatment # noqa line (a second copy of an already-present import).

@jeongyoonlee jeongyoonlee added the enhancement New feature or request label Jul 6, 2026

@jeongyoonlee jeongyoonlee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The p_value removal missed the docstrings — they still list a p_value column for return_ci=True. Please scrub the remaining references in cate_scoring.py:

  • _score_against_pseudo_outcome — the return_ci arg ("…confidence intervals and p-values") and the Returns ("…CI bounds, and p-value (H0: loss = 0)…").
  • dr_score — the return_ci arg and the Returns (same two).
  • plug_in_t_score — the return_ci arg and the Returns (same two).

Also the _score_against_pseudo_outcome summary line still says it "mirrors the half-sample bootstrap CI/p-value pattern in rate.py" — drop the p-value half.

@aman-coder03 aman-coder03 requested a review from jeongyoonlee July 7, 2026 17:26
@jeongyoonlee jeongyoonlee merged commit b13b4c6 into uber:master Jul 7, 2026
7 checks passed
@aman-coder03 aman-coder03 deleted the feature/cate-scoring-dr-plugin-t branch July 7, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CATE model selection via surrogate metrics (R-score, DR-loss)

2 participants