Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CausalTree split criterions fix and fit optimization #557

Merged
merged 7 commits into from Oct 21, 2022

Conversation

alexander-pv
Copy link
Collaborator

@alexander-pv alexander-pv commented Oct 8, 2022

Proposed changes

Hi, this PR contains several fixes for causal trees issues I have recently found:

  1. It turned out that sum_total and sq_sum_total attributes in RegressionCriterion were calculated using weights as multipliers. However, in CausalTree these weights have two values: eps for control, 1 for treatment. So, total outcome values for a tree split were incorrect. Link: _criterion.pyx

  2. There was incorrect calculation of weighted_n_node_samples attribute in RegressionCriterion. It is important to get the right impurity values and feature importance. Links: _criterion.pyx, _tree.pyx

  3. There is a more efficient way of calculating node and children impurity for each split. CausalTree fit() measurements clearly show this:

CausalTree_optimization_time
Additional code for time measurements: test.zip
Related issue: #541.

So, I added NodeInfo and SplitState structs in criterion.pyx for clarity and updated CausalRegressionCriterion. These steps allowed me to get rid of the loops in CausalMSE and even make this class more concise.

Curiously, the qini score with synthetic data has slightly changed since this update.
CausalTree_optimization_score
CausalTree_bugfix_boxplot

Additional updates:

  • CausalTreeRegressor fit_predict() method calculates bootstrap-based treatment effect along with bootstrap-based bounds.
  • Notebooks with causal trees
  • Tests for causal trees
  • Minor update in conftest.py to get the desired type of regression synthetic data in any test file.

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

@jeongyoonlee jeongyoonlee self-requested a review October 14, 2022 17:22
Copy link
Collaborator

@jeongyoonlee jeongyoonlee left a comment

Choose a reason for hiding this comment

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

This is great! Thanks for your contribution. I left one comment regarding the use of the bootstrapped mean. Otherwise, LGTM.

Thanks!

causalml/inference/tree/causal/causaltree.py Outdated Show resolved Hide resolved
@jeongyoonlee jeongyoonlee self-requested a review October 17, 2022 22:36
Copy link
Collaborator

@jeongyoonlee jeongyoonlee 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants