Skip to content

Fix incorrect bootstrap mean calculation in meta-learners#829

Merged
jeongyoonlee merged 1 commit into
masterfrom
jeong/fix_828
May 14, 2025
Merged

Fix incorrect bootstrap mean calculation in meta-learners#829
jeongyoonlee merged 1 commit into
masterfrom
jeong/fix_828

Conversation

@jeongyoonlee
Copy link
Copy Markdown
Collaborator

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 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

Copy link
Copy Markdown

Copilot AI left a comment

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 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

Copy link
Copy Markdown
Collaborator

@ras44 ras44 left a comment

Choose a reason for hiding this comment

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

LGTM 👍 thanks!

@jeongyoonlee jeongyoonlee merged commit 7f3385e into master May 14, 2025
14 checks passed
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.

Bug in causalml.inference.meta: Incorrect bootstrap confidence interval calculation in S/T/X/R-Learners

3 participants