causalml
causalml copied to clipboard
Cannot call causalml.inference.tree or causalml.dataset
Describe the bug
A clear and concise description of what the bug is.
Hey I followed exactly steps listed here https://github.com/uber/causalml but I get bugs when I run this line from causalml.dataset import synthetic_data
but I got an error saying ValueError: sklearn.tree._tree.TreeBuilder size changed, may indicate binary incompatibility. Expected 80 from C header, got 72 from PyObject
To Reproduce
Steps to reproduce the behavior:
$ git clone https://github.com/uber/causalml.git
$ cd causalml
$ pip install -r requirements.txt
$ pip install causalml
from causalml.dataset import synthetic_data
from causalml.inference.tree import UpliftTreeClassifier, UpliftRandomForestClassifier
Expected behavior A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):
- OS: [e.g. macOS]
- Python Version: [3.7.3]
- sklearn:1.0.2
- causalml:0.13.0
Additional context Pls help fix it
same problem
I also have this problem
What numpy version are you running? A quick solve could be upgrading your numpy version.
Hi everyone, My code is working from google colab. Please try this code-
! git clone https://github.com/uber/causalml.git ! cd causalml ! pip install -r /content/causalml/requirements-test.txt ! pip install causalml[tf] ! pip install -U numpy==1.23.5
same problem
Initially run the following code:
!pip install Causalml !pip install numpy==1.23.5
!git clone https://github.com/uber/causalml.git !cd causalml !pip install -r /content/causalml/requirements.txt !python setup.py build_ext --inplace !pip /content/causalml/setup.py install !python setup.py install
! git clone https://github.com/uber/causalml.git ! cd causalml ! pip install -r /content/causalml/requirements-test.txt ! pip install causalml[tf] ! pip install -U numpy==1.23.5
!pip install numpy==1.23.4
!pip install -U scikit-learn==1.0.2
!pip uninstall scikit-learn !pip install scikit-learn==1.0.2
when show- Proceed (Y/n)? Put Y and then enter; Then run-
import pandas as pd import numpy as np from matplotlib import pyplot as plt import seaborn as sns import torch
from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from xgboost import XGBRegressor from lightgbm import LGBMRegressor from sklearn.metrics import mean_absolute_error from sklearn.metrics import mean_squared_error as mse from scipy.stats import entropy import warnings import logging
from causalml.inference.meta import BaseXRegressor, BaseRRegressor, BaseSRegressor, BaseTRegressor from causalml.inference.nn import CEVAE from causalml.propensity import ElasticNetPropensityModel from causalml.metrics import * from causalml.dataset import simulate_hidden_confounder
%matplotlib inline
warnings.filterwarnings('ignore') logger = logging.getLogger('causalml') logger.setLevel(logging.DEBUG)
plt.style.use('fivethirtyeight') sns.set_palette('Paired') plt.rcParams['figure.figsize'] = (12,8)
When it is not running, go to "Runtime" and click on "Restart and run all"
It will definitely work in google colab, but do not forget # when show- Proceed (Y/n)? Put Y and then enter
hi @jakirhasantalukder I also encounter this issue. I successfully install causalml, but I cannot call causalml.inference.tree.
numpy version: 1.23.5 scikit-learn: 1.0.2 I receive the following errors when calling the class in causalml.inference.tree: from causalml.inference.tree import CausalTreeRegressor Traceback (most recent call last):
Input In [1] in <cell line: 1> from causalml.inference.tree import CausalTreeRegressor
File ~\Anaconda3\lib\site-packages\causalml\inference\tree_init_.py:1 in
File ~\Anaconda3\lib\site-packages\causalml\inference\tree\causal\causaltree.py:14 in
File ~\Anaconda3\lib\site-packages\causalml\inference\meta_init_.py:1 in
File ~\Anaconda3\lib\site-packages\causalml\inference\meta\slearner.py:9 in
File ~\Anaconda3\lib\site-packages\causalml\inference\meta\base.py:6 in
File ~\Anaconda3\lib\site-packages\causalml\inference\meta\explainer.py:2 in
File ~\Anaconda3\lib\site-packages\shap_init_.py:5 in
File ~\Anaconda3\lib\site-packages\shap_explanation.py:13 in
File ~\Anaconda3\lib\site-packages\shap\utils_init_.py:1 in
File ~\Anaconda3\lib\site-packages\shap\utils_clustering.py:7 in
File ~\Anaconda3\lib\site-packages\numba_init_.py:200 in
File ~\Anaconda3\lib\site-packages\numba_init_.py:140 in _ensure_critical_deps raise ImportError("Numba needs NumPy 1.21 or less")
ImportError: Numba needs NumPy 1.21 or less
If I install numpy==1.20.1, I receive the following errors: from causalml.inference.tree import CausalTreeRegressor Traceback (most recent call last):
Input In [1] in <cell line: 1> from causalml.inference.tree import CausalTreeRegressor
File ~\Anaconda3\lib\site-packages\causalml\inference\tree_init_.py:1 in
File ~\Anaconda3\lib\site-packages\causalml\inference\tree\causal\causaltree.py:15 in
File ~\Anaconda3\lib\site-packages\causalml\inference\tree\causal_tree.py:16 in
File causalml\inference\tree\causal_builder.pyx:1 in init causalml.inference.tree.causal._builder
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
Could you please help me with it?
Hi, I am a databricks user and attempted to install causalml library using
%pip install causalml numpy==1.20.3
which generated the follwoing error when I attempted to load casualml.dataset
from causalml.dataset import synthetic_data
Error:
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
I also attempted to install a newer version of numpy:
%pip install causalml numpy==1.23.5
which generated the following error:
ImportError: cannot import name '_centered' from 'scipy.signal.signaltools' (/local_disk0/.ephemeral_nfs/envs/pythonEnv-a32dc5df-a476-437e-ad17-39bfbcff6a58/lib/python3.8/site-packages/scipy/signal/signaltools.py
Can you please help me?
i cannot run the S-learner in my code. I wrote the code below for my dataset, which is attached to this comment.
import pandas as pd
Load your dataset
file_path = r'/content/prices (2).csv' your_data = pd.read_csv(file_path)
Assign columns to X and y
y = your_data['HolidayFlag'] X = your_data['SMPEP2'] prices (2).csv
Ready-to-use S-Learner using LinearRegression
learner_s = LRSRegressor() ate_s = learner_s.estimate_ate(X=X, treatment=treatment, y=y) print(ate_s) print('ATE estimate: {:.03f}'.format(ate_s[0][0])) print('ATE lower bound: {:.03f}'.format(ate_s[1][0])) print('ATE upper bound: {:.03f}'.format(ate_s[2][0]))
After calling estimate_ate, add pretrain=True flag to skip training
This flag is applicable for other meta learner
ate_s = learner_s.estimate_ate(X=X, treatment=treatment, y=y, pretrain=True) print(ate_s) print('ATE estimate: {:.03f}'.format(ate_s[0][0])) print('ATE lower bound: {:.03f}'.format(ate_s[1][0])) print('ATE upper bound: {:.03f}'.format(ate_s[2][0]))
the below error recived;
IndexError Traceback (most recent call last)
1 frames /usr/local/lib/python3.10/dist-packages/causalml/inference/meta/slearner.py in fit(self, X, treatment, y, p) 84 mask = (treatment == group) | (treatment == self.control_name) 85 treatment_filt = treatment[mask] ---> 86 X_filt = X[mask] 87 y_filt = y[mask] 88
IndexError: boolean index did not match indexed array along dimension 0; dimension is 10000 but corresponding boolean dimension is 9885
could anybody help me with that?
I'm using the code in https://github.com/uber/causalml/blob/master/docs/examples/meta_learners_with_synthetic_data.ipynb.
but when i wanted to run the slearner for the datset
prices (2).csv
.in my dataset, HolidayFlag' dataset is y and SMPEP2 is X.
I recieved the below error for the above code
Could you please help me with that?