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

Problem about calling Why.fit() #33

Closed Vihagle closed 1 year ago

Vihagle commented 2 years ago

Please make sure that this is a bug.

System information

Describe the current behavior

Describe the expected behavior

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Jupyter notebook.

Are you willing to submit PR?(Yes/No)

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

lixfz commented 2 years ago

Can you "Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Jupyter notebook."?

Vihagle commented 2 years ago

OK, I have sent an email to lixf@sovon.net with attachment, plz check~

lixfz commented 2 years ago

I found code in your notebook:

treatment = ['CRIM']
instrument = ['RM']
why = Why(random_state=2022)
why.fit(data, 'Price', treatment = treatment, instrument = instrument)

The reason for this exception is that you set argument instrument but not covariate.

If you set any of the adjustment/covariate/instrument during fiting, Why will skip identify step, so you should also set the others.

try code below

treatment = ['CRIM']
instrument = ['RM']
covariate = [c for c in data.columns.tolist() if c not in  treatment+instrument+['Price'] ]
why = Why(random_state=2022)
why.fit(data, 'Price', treatment = treatment, instrument = instrument, covariate=covariate)