Move calibrate() inside the PropensityModel class#839
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the calibration logic for propensity scoring by moving the calibration functionality inside the PropensityModel class and its descendants while removing the externally controlled calibrate_propensity parameter in various functions and examples.
- Merges calibration into PropensityModel and updates its descendants (ElasticNet, GradientBoosted) with a new calibrate parameter.
- Updates tests, documentation, and TMLE methods to remove the redundant calibration flags.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_visualize.py | Removed calibrate_propensity parameter from function calls. |
| docs/examples/validation_with_tmle.ipynb | Updated examples to remove deprecated calibration import and flag. |
| causalml/propensity.py | Moved calibration into PropensityModel; added calibrate parameter and removed standalone calibrate function. |
| causalml/metrics/visualize.py | Removed calibration flag when instantiating TMLELearner. |
| causalml/inference/meta/tmle.py | Removed calibration logic from TMLELearner in favor of internal calibration. |
Comments suppressed due to low confidence (1)
causalml/propensity.py:20
- [nitpick] Consider clarifying in the PropensityModel docstring that the calibrate parameter controls calibration during training only, and that the fitted calibrator is used to transform predictions rather than being re-fitted during predict().
calibrate (bool): whether calibrate the propensity score
Collaborator
Author
|
The build is failing because the latest scipy 1.16 breaks statsmodels (ref: statsmodels/statsmodels#9542 scipy/scipy#22557). Need to pin scipy to be < 1.16 until statsmodels fixes it. |
…on.validate_data and pin sklearn to be >= 1.6.0
paullo0106
reviewed
Jul 5, 2025
paullo0106
approved these changes
Jul 5, 2025
paullo0106
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, left a question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
This PR fixes #838, which was caused by #811 because it returned
p_model == Noneafter calibration, which was needed in an estimator like X-learner.The changes include:
propensity.calibrate()and output clipping are removed fromcompute_propensity_score()and to thePropensityModelclass.p, the propensity score, as an input and calibration should be done before getting passed to TMLELearner.With this change, if a propensity model object is provided in
compute_propensity_score(), it should handle calibration and output clipping.In addition, this PR fixes build errors caused by the recent updates in scipy and scikit-learn by
sklearn.base.BaseEstimator._validate_data()withsklearn.utils.validation.validate_data(), introduced inscikit-learn==1.6.0scipyto<1.16.0untilstatsmodelsupdates its API.Types of changes
What types of changes does your code introduce to CausalML?
Put an
xin the boxes that applyChecklist
Put an
xin 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.Further comments
N/A