uber / causalml

Uplift modeling and causal inference with machine learning algorithms
Other
4.99k stars 769 forks source link

ValueError: assignment destination is read-only #393

Closed chanansh closed 10 months ago

chanansh commented 2 years ago

Describe the bug estimate ate for sleaner produces an error: ValueError: assignment destination is read-only

~/.local/lib/python3.8/site-packages/causalml/inference/meta/slearner.py in predict(self, X, treatment, y, p, return_components, verbose)
    317 
    318             # set the treatment column to one (the treatment group)
--> 319             X_new[:, 0] = 1
    320             yhat_ts[group] = model.predict_proba(X_new)[:, 1]
    321 
**ValueError: assignment destination is read-only**

To Reproduce call slearner with :

base_learner = CatBoostClassifier(verbose=False, iterations = 50, random_state=42)
model = BaseSClassifier(learner=base_learner.copy())
te, lb, ub = model.estimate_ate(X=X, treatment=treatment, y=y)

The same data works when T-learner is used

Expected behavior estimate ate should return

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information): Package Version


absl-py 0.9.0 aiobotocore 1.3.3 aiohttp 3.7.3 aioitertools 0.7.1 alembic 1.4.1 anaconda-client 1.7.2 anaconda-navigator 1.10.0 anyio 2.0.2 appdirs 1.4.4 appnope 0.1.2 argon2-cffi 20.1.0 argopt 0.6.2 asn1crypto 1.4.0 astor 0.8.1 async-generator 1.10 async-timeout 3.0.1 attrs 20.3.0 autopep8 1.5.4 awsmfa 0.2.9 awswrangler 2.9.0 azure-core 1.9.0 azure-storage-blob 12.6.0 Babel 2.9.0 backcall 0.2.0 backports.entry-points-selectable 1.1.0 backports.functools-lru-cache 1.6.1 beautifulsoup4 4.9.3 bleach 3.2.1 blis 0.7.4 boto3 1.17.62 botocore 1.20.106 Bottleneck 1.3.2 brotlipy 0.7.0 CacheControl 0.12.6 cachetools 4.1.0 cachy 0.3.0 catalogue 2.0.4 catboost 0.24.2 causalml 0.11.1 certifi 2021.5.30 cffi 1.14.4 chardet 3.0.4 chart-studio 1.1.0 cleo 0.8.1 click 7.1.2 clikit 0.6.2 cloudpickle 1.6.0 clyent 1.2.2 cnvrg 0.7.13 colorama 0.4.4 colorlover 0.3.0 conda 4.10.3 conda-build 3.20.5 conda-package-handling 1.7.2 conda-verify 3.1.1 configparser 5.0.2 confuse 1.5.0 crashtest 0.3.1 cryptography 3.3.1 cufflinks 0.17.3 cycler 0.10.0 cymem 2.0.5 Cython 0.29.24 databricks-cli 0.14.0 datefinder 0.7.1 decorator 4.4.2 defusedxml 0.6.0 Deprecated 1.2.11 dill 0.3.3 distlib 0.3.2 docker 5.0.0 docker-pycreds 0.4.0 docutils 0.15.2 dowhy 0.2 econml 0.7.0 entrypoints 0.3 et-xmlfile 1.0.1 fastcache 1.1.0 filelock 3.0.12 fire 0.3.1 Flask 1.1.2 fsspec 0.8.5 funcy 1.16 future 0.18.2 gast 0.2.2 gensim 3.8.3 git-fame 1.14.0 gitdb 4.0.7 GitPython 3.1.18 glob2 0.7 gmpy2 2.1.0b1 google-api-core 1.23.0 google-auth 1.14.2 google-cloud-bigquery 1.24.0 google-cloud-core 1.4.3 google-cloud-storage 1.33.0 google-crc32c 1.0.0 google-pasta 0.2.0 google-resumable-media 1.1.0 googleapis-common-protos 1.51.0 graphviz 0.14 greenlet 1.1.0 grpcio 1.28.1 gunicorn 20.1.0 h5py 2.10.0 html5lib 1.0.1 htmlmin 0.1.12 idna 2.10 ImageHash 4.2.0 imbalanced-learn 0.8.0 importlib-metadata 1.7.0 ipykernel 5.4.2 ipython 7.19.0 ipython-genutils 0.2.0 ipywidgets 7.6.2 isodate 0.6.0 itsdangerous 2.0.1 jdcal 1.4.1 jedi 0.18.0 Jinja2 2.11.2 jmespath 0.10.0 joblib 1.0.0 json5 0.9.5 jsonschema 3.2.0 jupyter-client 6.1.7 jupyter-console 6.2.0 jupyter-contrib-core 0.3.3 jupyter-contrib-nbextensions 0.5.1 jupyter-core 4.7.0 jupyter-highlight-selected-word 0.2.0 jupyter-latex-envs 1.4.6 jupyter-nbextensions-configurator 0.4.1 jupyter-server 1.1.3 jupyterlab 3.0.0 jupyterlab-pygments 0.1.2 jupyterlab-server 2.0.0 jupyterlab-widgets 1.0.0 JustCause 0.4 Keras 2.3.1 Keras-Applications 1.0.8 Keras-Preprocessing 1.1.0 keyring 21.8.0 kiwisolver 1.3.1 kmodes 0.11.0 libarchive-c 2.9 lightgbm 3.0.0 llvmlite 0.35.0 lockfile 0.12.2 lxml 4.6.3 Mako 1.1.4 Markdown 3.2.1 MarkupSafe 1.1.1 matplotlib 3.3.3 missingno 0.4.2 mistune 0.8.4 mlflow 1.19.0 mlxtend 0.18.0 mpmath 1.1.0 msgpack 1.0.2 msrest 0.6.19 multidict 5.1.0 multimethod 1.4 murmurhash 1.0.5 navigator-updater 0.2.1 nb-conda-kernels 2.3.0 nbclassic 0.2.5 nbclient 0.5.1 nbconvert 6.0.7 nbformat 5.0.8 nest-asyncio 1.4.3 networkx 2.5 nltk 3.6.2 notebook 6.1.6 numba 0.52.0 numexpr 2.7.3 numpy 1.19.4 oauthlib 3.1.0 olefile 0.46 openpyxl 3.0.7 opt-einsum 3.2.1 packaging 20.8 pandas 1.2.5 pandas-profiling 3.0.0 pandocfilters 1.4.2 parso 0.8.1 pastel 0.2.1 pathy 0.6.0 patsy 0.5.1 pexpect 4.8.0 pg8000 1.19.5 phik 0.11.2 pickleshare 0.7.5 Pillow 8.0.1 pip 20.3.3 pkginfo 1.6.1 platformdirs 2.3.0 plotly 4.14.1 poetry 1.1.8 poetry-core 1.0.4 preshed 3.0.5 progress 1.5 progressbar2 3.53.1 prometheus-client 0.9.0 prometheus-flask-exporter 0.18.2 prompt-toolkit 3.0.8 protobuf 3.16.0 psutil 5.8.0 ptyprocess 0.7.0 pyaml 20.4.0 pyarrow 3.0.0 pyasn1 0.4.8 pyasn1-modules 0.2.8 pycaret 2.2.3 pycodestyle 2.6.0 pycosat 0.6.3 pycparser 2.20 pycryptodome 3.9.9 pydantic 1.8.2 pydot 1.4.1 pydotplus 2.0.2 pygam 0.8.0 PyGithub 1.54.1 Pygments 2.7.3 pyhcl 0.4.4 PyJWT 1.7.1 pyLDAvis 3.3.1 pylev 1.4.0 PyMySQL 1.0.2 pynndescent 0.5.4 pyod 0.9.0 pyOpenSSL 20.0.1 pyparsing 2.4.7 PyQt5 5.12.3 PyQt5-sip 4.19.18 PyQtChart 5.12 PyQtWebEngine 5.12.1 pyro-api 0.1.2 pyro-ppl 1.7.0 pyrsistent 0.17.3 PySocks 1.7.1 python-dateutil 2.8.1 python-editor 1.0.4 python-utils 2.4.0 pytz 2020.5 PyWavelets 1.1.1 PyYAML 5.3.1 pyzmq 20.0.0 qtconsole 5.0.1 QtPy 1.9.0 querystring-parser 1.2.4 redshift-connector 2.0.882 regex 2021.7.6 requests 2.25.1 requests-oauthlib 1.3.0 requests-toolbelt 0.9.1 retrying 1.3.3 rise 5.6.1 rsa 4.0 ruamel-yaml-conda 0.15.80 s3fs 0.5.2 s3transfer 0.4.2 scikit-learn 1.0 scipy 1.4.1 scramp 1.4.0 seaborn 0.11.0 Send2Trash 1.5.0 setuptools 49.6.0.post20201009 shap 0.37.0 shellingham 1.4.0 six 1.15.0 slicer 0.0.3 smart-open 5.1.0 smmap 3.0.5 sniffio 1.2.0 soupsieve 2.0.1 spacy 3.1.0 spacy-legacy 3.0.8 sparse 0.9.1 SQLAlchemy 1.4.21 sqlparse 0.4.1 srsly 2.4.1 statsmodels 0.12.1 sympy 1.6.2 tabulate 0.8.9 tangled-up-in-unicode 0.1.0 tenacity 8.0.1 tensorboard 1.15.0 tensorflow 1.15.2 tensorflow-estimator 1.15.1 termcolor 1.1.0 terminado 0.9.1 terraform-ci 1.3.1 testpath 0.4.4 textblob 0.15.3 thinc 8.0.7 threadpoolctl 2.1.0 tinynetrc 1.3.0 toml 0.10.1 tomlkit 0.7.2 torch 1.9.1 tornado 6.1 tqdm 4.55.0 traitlets 5.0.5 typer 0.3.2 typing-extensions 3.7.4.3 umap-learn 0.5.1 urllib3 1.25.11 virtualenv 20.7.2 visions 0.7.1 voila 0.2.7 wasabi 0.8.2 wcwidth 0.2.5 webencodings 0.5.1 websocket-client 0.57.0 Werkzeug 2.0.1 wheel 0.36.2 widgetsnbextension 3.5.1 wordcloud 1.8.1 wrapt 1.12.1 xgboost 1.3.0 xlrd 1.2.0 xmltodict 0.12.0 yapf 0.30.0 yarl 1.6.3 yellowbrick 1.3.post1 zipp 3.4.0

Additional context Add any other context about the problem here.

chanansh commented 2 years ago

changing the source code to

            # set the treatment column to zero (the control group)
            X_new = np.hstack((np.zeros((X.shape[0], 1)), X))**.copy()**

solved the issue.