-
Notifications
You must be signed in to change notification settings - Fork 332
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
Comments
that's weird. it appears there's a leaf with no observations. how many labels are in your target? |
2 labels : it is binary classification |
any chance I could get a small dataset that exhibits this behavior? |
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 |
oh sorry. read on my phone earlier. thanks! |
[deleted] i computed features wrong. still investigating...reproduced. |
Please |
@AlexandraBomane can you confirm it works? |
Hi @parrt, it works perfectly ! Many thanks for fixing the problem so quickly. |
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 ?
The text was updated successfully, but these errors were encountered: