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

IndexError: index 0 is out of bounds for axis 0 with size 0 #34

Closed
AlexandraBomane opened this issue Feb 25, 2019 · 9 comments
Closed
Labels
bug Something isn't working

Comments

@AlexandraBomane
Copy link

AlexandraBomane commented Feb 25, 2019

I trained a Sklearn CART model (using default parameters provided by Scikit-learn) on the attached data (data.txt, where the column "Target" contains the labels to predict, the rest of the columns containing the values associated with features).

For model fitting, I used :
from sklearn.tree import DecisionTreeClassifier
from sklearn.utils.class_weight import compute_sample_weight
clf = DecisionTreeClassifier(random_state = 374564)
clf.fit(data.drop(['Target'], axis = 1).values, data['Target'].values, sample_weight = compute_sample_weight("balanced", data['Target'].values))

I launched dtreeviz with the following command :
viz = dtreeviz(clf, data.drop(['Target'], axis = 1).values, data['Target'].values, target_name='pred', feature_names=feature_names, class_names=["Class1", "Class2"])

Then I got the following error message :
Traceback (most recent call last):
File "", line 1, in
File "/home/bomane/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py", line 373, in dtreeviz
filename=f"{tmp}/leaf{node.id}_{getpid()}.svg")
File "/home/bomane/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py", line 543, in class_leaf_viz
draw_piechart(node.class_counts(), size=size, colors=colors, filename=filename, label=f"n={node.nsamples()}")
File "/home/bomane/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py", line 728, in draw_piechart
i = np.nonzero(counts)[0][0]
IndexError: index 0 is out of bounds for axis 0 with size 0

Can you please tell me what could be the problem here ?

@parrt
Copy link
Owner

parrt commented Feb 25, 2019

that's weird. it appears there's a leaf with no observations. how many labels are in your target?

@AlexandraBomane
Copy link
Author

2 labels : it is binary classification

@parrt
Copy link
Owner

parrt commented Feb 25, 2019

any chance I could get a small dataset that exhibits this behavior?

@AlexandraBomane
Copy link
Author

In my first message, I provided the exact dataset (data.txt) that I'm using and which leads to the error. It contains only 57 rows and 17 columns

@parrt
Copy link
Owner

parrt commented Feb 25, 2019

oh sorry. read on my phone earlier. thanks!

@parrt
Copy link
Owner

parrt commented Feb 25, 2019

[deleted] i computed features wrong. still investigating...reproduced.

@parrt parrt closed this as completed in bb0e354 Feb 25, 2019
@parrt parrt added the bug Something isn't working label Feb 25, 2019
@parrt
Copy link
Owner

parrt commented Feb 25, 2019

Please pip install -U dtreeviz. Should work now. thanks!

@parrt
Copy link
Owner

parrt commented Feb 28, 2019

@AlexandraBomane can you confirm it works?

@AlexandraBomane
Copy link
Author

Hi @parrt, it works perfectly !

Many thanks for fixing the problem so quickly.

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

2 participants