py-why / dowhy

DoWhy is a Python library for causal inference that supports explicit modeling and testing of causal assumptions. DoWhy is based on a unified language for causal inference, combining causal graphical models and potential outcomes frameworks.
https://www.pywhy.org/dowhy
MIT License
6.88k stars 916 forks source link

Counterfactual Reasoning with Categorical Variables #1146

Closed rudi-mac closed 3 months ago

rudi-mac commented 4 months ago

I have a observational dataset of continuous, boolean and categorical variables and my goal is to make "what-if" statements. I have fitted and refuted the graph using gcm.InvertibleStructuralCausalModel.

The nodes represented by categorical variables are assigned with "Classifier FCM" based on HistGradientBoostingClassifier. When I want to call the function gcm.counterfactual_samples, I get the following error:

AttributeError: 'ClassifierFCM' object has no attribute 'estimate_noise'

I assume this is somehow related to the noise terms. If I remove the categorical variables, it works.

Therefore, my question: How to make counterfactual statements from observational data in dowhy with categorical variables?

Please help!

Version information:

bloebp commented 4 months ago

Hi, for point-wise counterfactuals, we currently only support continuous variables (since one only obtains a distribution for categorical variables, not a point estimate). However, depending on the use case, you might want to consider using interventions instead, which also work with categorical variables: https://www.pywhy.org/dowhy/v0.11.1/user_guide/causal_tasks/what_if/interventions.html

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 14 days with no activity.

rudi-mac commented 3 months ago

Thanks a lot for the reply! This is very helpful!