Skip to content

Move calibrate() inside the PropensityModel class#839

Merged
jeongyoonlee merged 5 commits into
masterfrom
jeong/hotfix_838
Jul 5, 2025
Merged

Move calibrate() inside the PropensityModel class#839
jeongyoonlee merged 5 commits into
masterfrom
jeong/hotfix_838

Conversation

@jeongyoonlee

@jeongyoonlee jeongyoonlee commented Jun 28, 2025

Copy link
Copy Markdown
Collaborator

Proposed changes

This PR fixes #838, which was caused by #811 because it returned p_model == None after calibration, which was needed in an estimator like X-learner.

The changes include:

  • propensity.calibrate() and output clipping are removed from compute_propensity_score() and to the PropensityModel class.
  • Removing propensity score calibration from TMLELearner as it takes 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

  • Replacing sklearn.base.BaseEstimator._validate_data() with sklearn.utils.validation.validate_data(), introduced in scikit-learn==1.6.0
  • Pinning scipy to <1.16.0 until statsmodels updates its API.

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

N/A

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread causalml/propensity.py
@jeongyoonlee

Copy link
Copy Markdown
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.

Comment thread causalml/propensity.py

@paullo0106 paullo0106 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.

LGTM, left a question

@jeongyoonlee jeongyoonlee merged commit d4100b1 into master Jul 5, 2025
14 checks passed
@jeongyoonlee jeongyoonlee mentioned this pull request Jul 6, 2025
10 tasks
@jeongyoonlee jeongyoonlee deleted the jeong/hotfix_838 branch July 6, 2025 03:49
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.

X-Learner predict() method does not work

3 participants