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

Cannot use CausalTree as estimator #45

Closed Lllllp93 closed 1 year ago

Lllllp93 commented 1 year ago

I try to use CausalTree as the estimator in why(), but seems like CausalTree.estimate() got unexpected keyword arguments.

Here is my code:

why1=Why(estimator='tree') why1.fit(train_data,outcome,treatment='Card_Category') effect1=why1.causal_effect(control='Blue',return_detail=True)

and error msg:

Traceback (most recent call last): File "d:/06.Repo/YLearn-main/example_usages/case_study_bank.py", line 38, in effect1=why1.causal_effect(control='Blue',return_detail=True) File "C:\Users\peng.liu2\Anaconda3\envs\CV\lib\site-packages\ylearn_why.py", line 820, in causal_effect return self._causal_effect_discrete(test_data, treat, control, return_detail=return_detail) File "C:\Users\peng.liu2\Anaconda3\envs\CV\lib\site-packages\ylearn_why.py", line 850, in _causal_effect_discrete effect = est.estimate(data=test_data, treat=t, control=c) TypeError: estimate() got an unexpected keyword argument 'treat'

I found that CausalTree.estimate() only accept data and quantity as arguments, so how can I use CausalTree as the estimator in why()

lixfz commented 1 year ago

We have fixed this issue in the main branch which is not released yet. Upgrade ylearn from latest source code and try again please.

Lllllp93 commented 1 year ago

Hi, I just found an error after I upgrade Ylearn from latest source code, here is the error msg:


ModuleNotFoundError Traceback (most recent call last) Cell In [2], line 4 1 import numpy as np 2 import matplotlib.pyplot as plt ----> 4 from ylearn.estimator_model.causal_tree import CausalTree, CTCausalForest 5 from ylearn.exp_dataset.exp_data import sq_data 6 from ylearn.utils._common import to_df

File c:\Users\peng.liu2\Anaconda3\envs\CV\lib\site-packages\ylearn__init__.py:2 1 from ._version import version ----> 2 from ._why import Why

File c:\Users\peng.liu2\Anaconda3\envs\CV\lib\site-packages\ylearn_why.py:11 9 from ylearn import metric as M 10 from ylearn import sklearn_ex as skex ---> 11 from ylearn.causal_discovery import CausalDiscovery 12 from ylearn.causal_model import CausalModel, CausalGraph 13 from ylearn.effect_interpreter.policy_interpreter import PolicyInterpreter

ModuleNotFoundError: No module named 'ylearn.causal_discovery'

And I am not sure if there is a problem with my installation method. I just run python setup.py install with latest source code.

Lllllp93 commented 1 year ago

reopen for latest source code

lixfz commented 1 year ago

YLearn can be installed from source code with command:

cd <ylearn_source_dir>
pip install .

Note 1: c&c++ complier is required to build cython extension, so install microsoft visual C++ 2015 or higher on windows. see https://wiki.python.org/moin/WindowsCompilers for more details. Note 2: ylearn does not install torch by default on windows, so install it seperately with command pip install torch .