DataCanvasIO / YLearn

YLearn, a pun of "learn why", is a python package for causal inference
https://ylearn.readthedocs.io
Apache License 2.0
391 stars 75 forks source link

run case_study_bank.py plotting issue on Mac #27

Closed JianxunSu closed 2 years ago

JianxunSu commented 2 years ago

There is a issue happened when run case_study_bank.py on Mac Machine: MacOS Monterey 12.3.1 Python 3.10 Errors as following:

why.plot_causal_graph()

... 07-17 17:18:23 I ylearn._why.py 508 - encode treatment ... 07-17 17:18:23 I ylearn._why.py 518 - preprocess data ... 07-17 17:18:24 I ylearn._why.py 536 - fit estimator for Card_Category with PermutedTLearner(model=GradientBoostingRegressor(max_depth=100), random_state=2022, kwargs=None) /Users/jevin/dev/python/ai/YLearn/ylearn/utils/_common.py:95: UserWarning: Failed to display pydot image: [Errno 2] "fdp" not found in path.. warnings.warn(f'Failed to display pydot image: {e}.')

JianxunSu commented 2 years ago

The training is okay, can't plot the causal graph

lixfz commented 2 years ago

graphviz is required to plot causal graph, see http://www.graphviz.org/download/ for more details.

If your python env was created with conda, you can also install graphviz with command :

conda install graphviz 
JianxunSu commented 2 years ago

Yes, it works, Thanks! So should the graphviz be included in requirements.txt or is this just a library needed for MacOS? I uploaded this notebook to Google Colab run successfully, it needn't ask me to install graphviz, the only library manually installed is just ylearn. @lixfz

lixfz commented 2 years ago

The graphviz is an operating system dependent software, can not be installed through pip command. Generally, it should be installed through the os's package manager.

Google Colab has installed the graphviz by default,so we can use it directly.

JianxunSu commented 2 years ago

Ok, Thanks for explanation!

JianxunSu commented 2 years ago

By the way, I did install graphviz on my MacOs with "pip install graphviz" and pycharm python package, like following: (venv) jevin@JSU YLearn (main) $ pip install graphviz Collecting graphviz Using cached graphviz-0.20-py3-none-any.whl (46 kB) Installing collected packages: graphviz Successfully installed graphviz-0.20 @lixfz

If I remove this graphviz-0.20 python library, it will generate the original error again.

I think I have installed OS level graphviz already(before downloading YLearn), this python library installation only provide an interface, is that correct?

lixfz commented 2 years ago

The pip installed graphviz is just a python wrapper of os native graphviz.

The description from pypi:

image

@JianxunSu

JianxunSu commented 2 years ago

@lixfz in my case, the pip install helped, so I should install the os package already.