Skip to content

Apply clip_bounds to a user-supplied propensity model - #1043

Open
arpitjain099 wants to merge 1 commit into
uber:masterfrom
arpitjain099:fix/clip-user-propensity
Open

arpitjain099 wants to merge 1 commit into
uber:masterfrom
arpitjain099:fix/clip-user-propensity

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

compute_propensity_score documents clip_bounds as keeping the score away from 0 and 1 so later steps do not divide by zero, but the bound only applies when the default model is used. PropensityModel.predict clips internally; a user-supplied classifier goes through predict_proba and its output is returned untouched.

On a separable treatment that saturates:

p_user, _ = compute_propensity_score(X=X, treatment=w, p_model=LogisticRegression(C=1e9, max_iter=1000))
p_def, _ = compute_propensity_score(X=X, treatment=w)
p_user.min(), p_user.max()   # 0.0, 1.0
p_def.min(), p_def.max()     # 0.001, 0.999

Feeding the first one back into the library rejects it, which is what the bound was there to prevent:

BaseDRRegressor(learner=LinearRegression()).fit_predict(X=X, treatment=w, y=y, p=p_user)
AssertionError: The values of p should lie within the (0, 1) interval.

The DR-learner divides by both p_filt and 1 - p_filt, and TMLE by p and 1 - p, so the guard is the only thing standing between a saturated propensity model and an infinity.

The returned score is now clipped whichever model produced it. For the built-in models this is a no-op, since predict has already clipped to the same bounds. BaseRLearner(propensity_learner=...) reaches the unclipped path through self.model_p, so it is covered too.

Two tests: a user-supplied LogisticRegression on separable data has to come back inside the default bounds, which fails on master with assert np.float64(0.0) >= 0.001, and custom bounds have to hold as well.

pytest tests/test_propensity.py tests/test_cate_scoring.py is 39 passing, and black is clean on both files.

@jeongyoonlee
jeongyoonlee self-requested a review October 3, 2026 19:55
@jeongyoonlee

Copy link
Copy Markdown
Collaborator

Sorry for the delayed response, @arpitjain099. Can you please rebase this PR onto the latest master? I will review and approve it once the conflict is resolved.

@jeongyoonlee jeongyoonlee added the bug Something isn't working label Oct 4, 2026
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099
arpitjain099 force-pushed the fix/clip-user-propensity branch from 1e4a7e1 to 252e4b6 Compare October 20, 2026 07:50
@arpitjain099

Copy link
Copy Markdown
Contributor Author

Rebased onto master. The only conflict was at the end of tests/test_propensity.py, where the early stopping tests from #1051 and mine both append in the same place, so I kept both. propensity.py applied cleanly. Without the change the two new tests still fail at HEAD, p.min() comes back 0.0, and with it test_propensity.py plus test_cate_scoring.py is 41 passing against 39 on master.

@arpitjain099

Copy link
Copy Markdown
Contributor Author

@jeongyoonlee please see if you can review this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants