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

Add propensity_learner to R-learner. #297

Merged
merged 1 commit into from Feb 3, 2021
Merged

Conversation

jeongyoonlee
Copy link
Collaborator

Proposed changes

Since propensity modeling takes an important role in R-learner, it'd be better if users can define which learner to use for propensity modeling. This PR includes:

  • add propensity_learner as an input argument to BaseRLearner with ElasticNetPropensityModel as default.
  • refactor R/X-learners by defining _set_propensity_models() and _format_p() in BaseLearner.

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

…nce.meta. refactoring R/X learners accodringly
w_filt = (treatment_filt == group).astype(int)
w = (treatment == group).astype(int)
propensity_model = self.model_p if hasattr(self, 'model_p') else None
p[group], p_model[group] = compute_propensity_score(X=X_filt, treatment=w_filt,
Copy link
Collaborator

@ppstacy ppstacy Feb 3, 2021

Choose a reason for hiding this comment

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

Hi @jeongyoonlee a quick question that might not be directly related to this PR. Why do we need two treatment and treatment_pred here? Aren't those the same thing based on here: https://github.com/uber/causalml/blob/master/causalml/propensity.py#L189?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this call to compute_propensity_score(), treatment is only for the filtered samples with treatment belonging to either the control group or treatment group of interest while treatment_pred is for the entire samples. These two will be the same for a single treatment, but different for the multiple treatments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gotcha I see. Sorry a follow-up question here, why do we need to calibrate it with the entire dataset? I am asking because we are only using treatment group X + control when running the model in https://github.com/uber/causalml/blob/master/causalml/inference/meta/rlearner.py#L111-L118.

Copy link
Collaborator

@ppstacy ppstacy 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 829b2ca into master Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants