py-why / py-why/EconML

AttributeError: 'CausalEstimate' object has no attribute '_estimator_object' when using DoWhy integration

Open
#545 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.8k
Forks
827
PR merge metrics
No merged PRs in 30d

Description

Hi! First of all, thanks for the wonderful packages econml and dowhy!

When trying to follow the example of "Case Study - Customer Segmentation at An Online Media Company - EconML + DoWhy" notebook on my own data, I run

# initiate an EconML cate estimator
est_nonparam = CausalForestDML(model_y=GradientBoostingRegressor(), model_t=GradientBoostingClassifier(), discrete_treatment=True,)
# fit through dowhy
est_nonparam_dw = est_nonparam.dowhy.fit(y, T, X=X, W=W, outcome_names=[outcome], treatment_names=[treatment],
                                         feature_names=features_X, confounder_names=features_float, inference="blb")
point = est_nonparam_dw.effect(X)
lb, ub = est_nonparam_dw.effect_interval(X)

but this generates the below error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\Users\EGOR~1.KRA\AppData\Local\Temp/ipykernel_57188/1486408213.py in <module>
      4 est_nonparam_dw = est_nonparam.dowhy.fit(y, T, X=X, W=W, outcome_names=[outcome], treatment_names=[treatment],
      5                                          feature_names=features_X, confounder_names=features_float, inference="blb")
----> 6 point = est_nonparam_dw.effect(X)
      7 lb, ub = est_nonparam_dw.effect_interval(X)

~\.conda\envs\generic3.9\lib\site-packages\econml\dowhy.py in __getattr__(self, attr)
    223         elif attr.startswith('dowhy__'):
    224             return getattr(self.dowhy_, attr[len('dowhy__'):])
--> 225         elif hasattr(self.estimate_._estimator_object, attr):
    226             if hasattr(self.dowhy_, attr):
    227                 warnings.warn("This call is ambiguous, "

AttributeError: 'CausalEstimate' object has no attribute '_estimator_object'

Any idea what could be going wrong there? The code seems to be pretty exactly cut and paste from the notebook (except that the trreatment is categorical), but the code in the example notebook runs fine.

On the other hand,

est3 = CausalForestDML(model_y=GradientBoostingRegressor(), 
                       model_t=GradientBoostingClassifier(),
                       discrete_treatment=True,
                      )
est3.fit(y, T, X=X, W=W)
te_pred3 = est3.effect(X)
lb3, ub3 = est3.effect_interval(X, alpha=0.01)

runs fine, so it doesn't seem to be a data issue.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Case Study notebook flow with a categorical treatment, then inspect econml/dowhy.py around the getattr delegation shown in the traceback. Compare the failing dowhy-wrapped calls with the direct CausalForestDML calls; done means effect and effect_interval work through the DoWhy integration without the AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.