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

AttributeError: 'bool' object has no attribute 'sum' when use UpliftTreeClassifier fill() #810

Open
zz0807 opened this issue Jan 22, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@zz0807
Copy link

zz0807 commented Jan 22, 2025

Describe the bug
I used the fill() function of UpliftTreeClassifier according to the documentation, where the parameters are specified as NumPy arrays

However, I encountered a bug.

uplift_model.fill(X=X_val, treatment=treatment_val, y=y_val)
File "causalml/inference/tree/uplift.pyx", line 534, in causalml.inference.tree.uplift.UpliftTreeClassifier.fill
File "causalml/inference/tree/uplift.pyx", line 557, in causalml.inference.tree.uplift.UpliftTreeClassifier.fillTree
File "causalml/inference/tree/uplift.pyx", line 846, in causalml.inference.tree.uplift.UpliftTreeClassifier.tree_node_summary
File "causalml/inference/tree/uplift.pyx", line 667, in causalml.inference.tree.uplift.UpliftTreeClassifier.group_uniqueCounts
AttributeError: 'bool' object has no attribute 'sum'

To Reproduce
`import numpy as np
import pandas as pd
from causalml.inference.tree import UpliftTreeClassifier
from sklearn.model_selection import train_test_split

data = pd.DataFrame({
'feature1': np.random.rand(1000000),
'feature2': np.random.rand(1000000),
'treatment': np.random.choice([0, 1], 1000000),
'outcome': np.random.choice([0, 1], 1000000)
})

X = data[['feature1', 'feature2']]
treatment = np.where(data['treatment'] == 0, 'control', 'treatment') #
y = data['outcome']

X_train, X_val, treatment_train, treatment_val, y_train, y_val = train_test_split(
X, treatment, y, test_size=0.2, random_state=42
)

uplift_model = UpliftTreeClassifier(
max_depth=3,
min_samples_leaf=200,
min_samples_treatment=5,
n_reg=100,
evaluationFunction='KL',
control_name='control'
)

uplift_model.fit(X=X_train.values, treatment=treatment_train, y=y_train.values)

uplift_model.fill(X=X_val.values, treatment=treatment_val, y=y_val.values)`

Environment (please complete the following information):

  • OS:linux
  • Python Version: 3.7,7
@zz0807 zz0807 added the bug Something isn't working label Jan 22, 2025
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

1 participant