EconML CausalForestDML Estimation error
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]
I have the same problem. Have you solved it?
@andresmor-ms , could you take a look at this bug report?
@andresmor-ms , could you take a look at this bug report?
@andresmor-ms , could you take a look at this bug report?
![]()
![]()
@andresmor-ms , could you take a look at this bug report?
ValueError: This estimator does not support X=None!
@andresmor-ms , could you take a look at this bug report?
@emrekiciman , any help?
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.
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~
@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 @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_modifiersIf 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?
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
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'.
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
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'.
![]()
![]()
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.
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>)
