Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call causalml.inference.tree or causalml.dataset #615

Open
Cici-J-github opened this issue Apr 19, 2023 · 10 comments
Open

Cannot call causalml.inference.tree or causalml.dataset #615

Cici-J-github opened this issue Apr 19, 2023 · 10 comments
Labels
bug Something isn't working

Comments

@Cici-J-github
Copy link

Cici-J-github commented Apr 19, 2023

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.
Screenshot 2023-04-19 at 4 47 44 PM

Screenshot 2023-04-19 at 4 48 03 PM

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

@Cici-J-github Cici-J-github added the bug Something isn't working label Apr 19, 2023
@jakirhasantalukder
Copy link

same problem

@guilhermeresende
Copy link

I also have this problem

@xhulianoThe1
Copy link
Contributor

What numpy version are you running? A quick solve could be upgrading your numpy version.

@jakirhasantalukder
Copy link

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

@StarMaye
Copy link

StarMaye commented Jul 3, 2023

same problem

@jakirhasantalukder
Copy link

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

@MingyueHe
Copy link

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
from .causal.causaltree import CausalTreeRegressor

File ~\Anaconda3\lib\site-packages\causalml\inference\tree\causal\causaltree.py:14 in
from causalml.inference.meta.utils import check_treatment_vector

File ~\Anaconda3\lib\site-packages\causalml\inference\meta_init_.py:1 in
from .slearner import LRSRegressor, BaseSLearner, BaseSRegressor, BaseSClassifier

File ~\Anaconda3\lib\site-packages\causalml\inference\meta\slearner.py:9 in
from causalml.inference.meta.base import BaseLearner

File ~\Anaconda3\lib\site-packages\causalml\inference\meta\base.py:6 in
from causalml.inference.meta.explainer import Explainer

File ~\Anaconda3\lib\site-packages\causalml\inference\meta\explainer.py:2 in
import shap

File ~\Anaconda3\lib\site-packages\shap_init_.py:5 in
from ._explanation import Explanation, Cohorts

File ~\Anaconda3\lib\site-packages\shap_explanation.py:13 in
from .utils._exceptions import DimensionError

File ~\Anaconda3\lib\site-packages\shap\utils_init_.py:1 in
from ._clustering import (

File ~\Anaconda3\lib\site-packages\shap\utils_clustering.py:7 in
from numba import njit

File ~\Anaconda3\lib\site-packages\numba_init_.py:200 in
_ensure_critical_deps()

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
from .causal.causaltree import CausalTreeRegressor

File ~\Anaconda3\lib\site-packages\causalml\inference\tree\causal\causaltree.py:15 in
from ._tree import BaseCausalDecisionTree

File ~\Anaconda3\lib\site-packages\causalml\inference\tree\causal_tree.py:16 in
from ._builder import DepthFirstCausalTreeBuilder, BestFirstCausalTreeBuilder

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?

@kihaddadi
Copy link

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?

@ImanEmtiazi728
Copy link

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)
in <cell line: 3>()
1 # Ready-to-use S-Learner using LinearRegression
2 learner_s = LRSRegressor()
----> 3 ate_s = learner_s.estimate_ate(X=X, treatment=treatment, y=y)
4 print(ate_s)
5 print('ATE estimate: {:.03f}'.format(ate_s[0][0]))

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?

@ImanEmtiazi728
Copy link

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.
45

I recieved the below error for the above code

46

Could you please help me with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants