dowhy icon indicating copy to clipboard operation
dowhy copied to clipboard

EconML CausalForestDML Estimation error

Open ukamath opened this issue 3 years ago • 14 comments

Get an error while running the Lalonde dataset using the EconML Causal Forest estimator. Runs fine with all meta-learners.

Code

from dowhy import CausalModel from sklearn.ensemble import RandomForestRegressor

model=CausalModel( data = lalonde_df, treatment='treat', outcome='re78', common_causes='nodegr+black+hisp+age+educ+married'.split('+')) identified_estimand = model.identify_effect()

causalforest_learner_estimate = model.estimate_effect(identified_estimand, method_name="backdoor.econml.dml.CausalForestDML", confidence_intervals=False, method_params={ 'init_params': {'model_y': RandomForestRegressor(), 'model_t': RandomForestRegressor() }, 'fit_params': {} }) print(causalforest_learner_estimate)

Error /usr/local/lib/python3.8/dist-packages/econml/dml/causal_forest.py in fit(self, Y, T, X, W, sample_weight, groups, cache_values, inference) 831 """ 832 if X is None: --> 833 raise ValueError("This estimator does not support X=None!") 834 return super().fit(Y, T, X=X, W=W, 835 sample_weight=sample_weight, groups=groups,

ValueError: This estimator does not support X=None!

Version information:

  • DoWhy version [e.g. 0.9.1]

ukamath avatar Dec 22 '22 17:12 ukamath

I have the same problem. Have you solved it?

AzureLee11 avatar Feb 09 '23 08:02 AzureLee11

@andresmor-ms , could you take a look at this bug report?

emrekiciman avatar Feb 09 '23 08:02 emrekiciman

@andresmor-ms , could you take a look at this bug report? image

image

AzureLee11 avatar Feb 09 '23 09:02 AzureLee11

@andresmor-ms , could you take a look at this bug report?

image image

@andresmor-ms , could you take a look at this bug report?

AzureLee11 avatar Feb 10 '23 13:02 AzureLee11

ValueError: This estimator does not support X=None!

AzureLee11 avatar Feb 13 '23 07:02 AzureLee11

@andresmor-ms , could you take a look at this bug report?

@emrekiciman , any help?

AzureLee11 avatar Feb 23 '23 07:02 AzureLee11

Sorry for the delay, I don't know why I didn't get notified of this mention in the email, taking a look and will update as soon as possible.

andresmor-ms avatar Feb 24 '23 22:02 andresmor-ms

Sorry for the delay, I don't know why I didn't get notified of this mention in the email, taking a look and will update as soon as possible.

Thank you very much and wish you all the best~

AzureLee11 avatar Feb 27 '23 01:02 AzureLee11

@emrekiciman @AzureLee11

From my investigation, I discovered that on the econml wrapper we do this:

X = None  # Effect modifiers
if self._effect_modifiers is not None and len(self._effect_modifiers) > 0:
    X = self._effect_modifiers

If the CausalModel object does not contain the effect modifiers then X will be None, meaning that the estimator will fail with the error above.

The case for metalearners is that we have some specific logic for them that will set the effect_modifiers if the estimator comes from the metalearners package, and that's probably why you see the metarlearner estimators working.

andresmor-ms avatar Mar 02 '23 15:03 andresmor-ms

@emrekiciman @AzureLee11

From my investigation, I discovered that on the econml wrapper we do this:

X = None  # Effect modifiers
if self._effect_modifiers is not None and len(self._effect_modifiers) > 0:
    X = self._effect_modifiers

If the CausalModel object does not contain the effect modifiers then X will be None, meaning that the estimator will fail with the error above.

The case for metalearners is that we have some specific logic for them that will set the effect_modifiers if the estimator comes from the metalearners package, and that's probably why you see the metarlearner estimators working. @emrekiciman @andresmor-ms Thank you for your reply. So there's no way to use dowhy for the causal forest algorithm? Are there any suggested solutions?

AzureLee11 avatar Mar 10 '23 07:03 AzureLee11

Hi @AzureLee11 , when you create the CausalModel object, you can pass in effect_modifiers as a named parameter to the constructor. If you pass in the list of features you want to treat as effect modifiers, that should address this issue.

class CausalModel:

    """Main class for storing the causal model state."""

    def __init__(
        self,
        data,
        treatment,
        outcome,
        graph=None,
        common_causes=None,
        instruments=None,
        effect_modifiers=None,
        estimand_type="nonparametric-ate",
        proceed_when_unidentifiable=False,
        missing_nodes_as_confounders=False,
        identify_vars=False,
        **kwargs,

https://www.pywhy.org/dowhy/v0.9.1/dowhy.html#dowhy.CausalModel

emrekiciman avatar Mar 10 '23 18:03 emrekiciman

@emrekiciman @AzureLee11

Sorry I'm using the CausalForestDML of the package named economl to create the CausalModel object('CausalForest_estimate' in the pic below). And then I use economl.dowhy.fit, which got an unexpected keyword argument 'effect_modifiers'.

image image

Hi @AzureLee11 , when you create the CausalModel object, you can pass in effect_modifiers as a named parameter to the constructor. If you pass in the list of features you want to treat as effect modifiers, that should address this issue.

class CausalModel:

    """Main class for storing the causal model state."""

    def __init__(
        self,
        data,
        treatment,
        outcome,
        graph=None,
        common_causes=None,
        instruments=None,
        effect_modifiers=None,
        estimand_type="nonparametric-ate",
        proceed_when_unidentifiable=False,
        missing_nodes_as_confounders=False,
        identify_vars=False,
        **kwargs,

https://www.pywhy.org/dowhy/v0.9.1/dowhy.html#dowhy.CausalModel

AzureLee11 avatar Mar 11 '23 07:03 AzureLee11

@emrekiciman @AzureLee11

Sorry I'm using the CausalForestDML of the package named economl to create the CausalModel object('CausalForest_estimate' in the pic below). And then I use economl.dowhy.fit, which got an unexpected keyword argument 'effect_modifiers'.

image image

Hi @AzureLee11 , when you create the CausalModel object, you can pass in effect_modifiers as a named parameter to the constructor. If you pass in the list of features you want to treat as effect modifiers, that should address this issue.

class CausalModel:

    """Main class for storing the causal model state."""

    def __init__(
        self,
        data,
        treatment,
        outcome,
        graph=None,
        common_causes=None,
        instruments=None,
        effect_modifiers=None,
        estimand_type="nonparametric-ate",
        proceed_when_unidentifiable=False,
        missing_nodes_as_confounders=False,
        identify_vars=False,
        **kwargs,

https://www.pywhy.org/dowhy/v0.9.1/dowhy.html#dowhy.CausalModel

@emrekiciman @AzureLee11

While I used the parameter X in place of effect_modifiers, it reported "ValueError: This estimator does not support X=None!" That's the problem I met.

AzureLee11 avatar Mar 11 '23 07:03 AzureLee11

I see. I was thinking more like the example in this notebook: https://www.pywhy.org/dowhy/v0.9.1/example_notebooks/dowhy-conditional-treatment-effects.html#Works-with-any-EconML-method

and passing in the effect_modifiers parameter as an argument to the CausalModel object created in step 4 of the notebook:

model = CausalModel(data=data["df"],
                    treatment=data["treatment_name"], outcome=data["outcome_name"],
                    graph=data["gml_graph"],
                    effect_modifiers=<INSERTHERE>)

emrekiciman avatar Mar 14 '23 01:03 emrekiciman