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

Causal trees bootstrapping and max_leaf_nodes fixes with minor update #583

Merged
merged 14 commits into from
Dec 12, 2022

Conversation

alexander-pv
Copy link
Collaborator

@alexander-pv alexander-pv commented Nov 28, 2022

Proposed changes

Hi, my fix is aimed to solve recent causal trees issues.
I also added several updates to make causal trees more transparent and flexible for various tasks.

  • CausalRandomForestRegressor model had incorrect boostraping because of the wrong samples weightning mechanism.
    Code details are here.
    In general, this happened because samples weights are not used in causal trees as they are in common sklearn tree regressors.
    Now instead of using np.bincount(indices, minlength=n_samples) as weights multiplier _parallel_build_trees function generates the views of bootstraped X, y, treatment arrays. See here.

  • Non-default values of max_leaf_nodes don't break tree fit. To fix the issue CausalTree regression with 'max_leaf_nodes=xxx' doesn't work #567 sklearn BestFirstTreeBuilder class was modified into internal BestFirstCausalTreeBuilder.

  • min_samples_split parameter got updated behaviour based on treatment and control sample sizes in each tree node. Details can be found in DepthFirstCausalTreeBuilder and BestFirstCausalTreeBuilder. The fix is aimed to solve the issue of infinity node values which may happen in case of high imbalance of treatment and control sample size.

  • sklearn version in setup_requires setup.py was updated to <=1.0.2 from >=0.22.0. Probably, the related issue is binary incompatibility. Expected 352 from C header, got 328 from PyObject #581.

Minor update:

  • DepthFirstCausalTreeBuilder and BestFirstCausalTreeBuilder were improved to recognize a node split as a leaf with the use of auxiliary information about the number of treatment and control samples. This may be crucial in some bootstrapping cases during CausalRandomForestRegressor fit.
    Please, see here and here.

  • New groups_penalty parameter in CausalTreeRegressor and CausalRandomForestRegressor can be used to manage the balance between groups size (treatment and control) in each tree node. See here and here

  • Now CausalTreeRegressor and trees in CausalRandomForestRegressor class can be plotted with the information about the treatment and control sample sizes that were used to build a tree. See from this line.
    Add tree visualization for CausalTreeRegressor #357

Example from jupyter notebook:
ctree_plot_example

  • .pxd files were added to move most third-party cython imports and auxulliary declarations.

Although It's not quite fair to compare synthetic data results of this branch with the master, but causal trees were able to beat the previous successor DRLearner without much hyperparameters fine-tuning.

Screenshots from causal_trees_with_synthetic_data.ipynb:

Before:
cforest_scatterplot_0
cforest_example_0

After the changes:
cforest_scatterplot_1
cforest_example_1

Types of changes

  • 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

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc. This PR template is adopted from appium.

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