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

sklearn.tree.plot_tree does not work with econml.grf.CausalForest #938

Open
4Freye opened this issue Dec 10, 2024 · 2 comments · May be fixed by #939
Open

sklearn.tree.plot_tree does not work with econml.grf.CausalForest #938

4Freye opened this issue Dec 10, 2024 · 2 comments · May be fixed by #939

Comments

@4Freye
Copy link

4Freye commented Dec 10, 2024

Hello, I would like to plot a causal tree from a causal forest. I tried running the "1. Causal Forest: Heterogeneous causal effects with no unobserved confounders" section from this notebook but I receive an error when trying to plot a causal tree using plot_tree from sklearn.tree (see cell 8 in the notebook):

InvalidParameterError: The 'decision_tree' parameter of plot_tree must be an instance of 'sklearn.tree._classes.DecisionTreeClassifier' or an instance of 'sklearn.tree._classes.DecisionTreeRegressor'. Got GRFTree(criterion='het', max_features='auto', min_var_leaf_on_val=True,
random_state=1465622306) instead."

It seems that this worked in the past, perhaps this works with an older version of sklearn or econml? For reference, I am using sklearn version '1.4.2' and econml version '0.15.0'.

@kbattocchi
Copy link
Collaborator

Thanks for the report, and sorry for the inconvenience. Until we can address it on our end, I believe you should be able to work around it yourself by running

from sklearn.tree import DecisionTreeClassifier
from econml.grf._base_grftree import GRFTree
DecisionTreeClassifier.register(GRFTree)

before calling plot_tree. Could you see if this works for you?

@4Freye
Copy link
Author

4Freye commented Dec 10, 2024

Yes that solved the issue, thank you!

@kbattocchi kbattocchi linked a pull request Dec 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants