Fix incorrect bootstrap mean calculation in meta-learners#829
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the incorrect bootstrap mean calculation in several meta learner implementations and updates the abstract method decorator usage in the base class to address deprecation.
- Updated bootstrap mean calculation by specifying axis=0 in xlearner, tlearner, slearner, rlearner, and drlearner.
- Replaced deprecated @abstractclassmethod decorator with a combination of @classmethod and @AbstractMethod in the base learner.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Bumped version to "0.15.4dev". |
| causalml/inference/meta/xlearner.py | Fixed bootstrap mean calculation by adding axis=0. |
| causalml/inference/meta/tlearner.py | Fixed bootstrap mean calculation by adding axis=0. |
| causalml/inference/meta/slearner.py | Fixed bootstrap mean calculation by adding axis=0. |
| causalml/inference/meta/rlearner.py | Fixed bootstrap mean calculation by adding axis=0. |
| causalml/inference/meta/drlearner.py | Fixed bootstrap mean calculation by adding axis=0. |
| causalml/inference/meta/base.py | Replaced deprecated decorator with @classmethod and @AbstractMethod. |
Comments suppressed due to low confidence (6)
causalml/inference/meta/xlearner.py:393
- This change explicitly specifies the axis for the mean calculation, resolving the incorrect indexing issue in the bootstrap computation. Confirm that axis=0 correctly represents the intended dimension for averaging.
ate_bootstraps[:, n] = cate_b.mean(axis=0)
causalml/inference/meta/tlearner.py:283
- Specifying axis=0 ensures that the average is computed correctly across bootstrap samples. Verify that the array shape supports this change.
ate_bootstraps[:, n] = ate_b.mean(axis=0)
causalml/inference/meta/slearner.py:281
- The update to use mean(axis=0) properly indexes the bootstrap means. Please ensure that this aligns with the expected structure of ate_bootstraps.
ate_bootstraps[:, n] = ate_b.mean(axis=0)
causalml/inference/meta/rlearner.py:327
- Changing to mean(axis=0) corrects the averaging over bootstrap samples. Confirm that the intended dimension is being averaged.
ate_bootstraps[:, n] = cate_b.mean(axis=0)
causalml/inference/meta/drlearner.py:437
- The modification to include axis=0 in the mean computation clarifies the bootstrap averaging behavior. Check that this change consistently fixes the miscalculation.
ate_bootstraps[:, n] = cate_b.mean(axis=0)
causalml/inference/meta/base.py:15
- Replacing the deprecated @abstractclassmethod with a combination of @classmethod and @AbstractMethod aligns the code with current best practices. Verify that the new decorator order maintains the intended abstract behavior.
@classmethod
@abstractmethod
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 #828 - incorrect indexing of bootstrap mean calculation in meta learners. It also replaces deprecated @abstractclassmethod with @classmethod and @AbstractMethod.
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