dtreeviz
dtreeviz copied to clipboard
dtreeviz fails with IndexError for n_classes >= 11
Apparently dtreeviz
in dtreeviz.trees.py
fails on the following block of code:
> /home/macermak/.local/lib/python3.6/site-packages/dtreeviz/trees.py(320)dtreeviz()
318
319 n_classes = shadow_tree.nclasses()
--> 320 color_values = color_blind_friendly_colors[n_classes]
321
322 # Fix the mapping from target value to color for entire tree
resulting in
IndexError: list index out of range
My model has 15
classes and I believe the length of color_blind_friendly_colors
(which is 11
) is causing the issue.
ah. yeah, sorry. I should put a check in there but only 10 classes can be handled right now. we had to handpick the colors. sorry about that.
Wow, quick response!
So there is nothing I can do at the moment?
Nope :( sorry.
Okay, let's hope for a quick solution in the bright future. Keep up the good work and thanks for the quick response.
thanks :) I'd be happy to accept a pull request that increased the number of color palettes ;)
It's a bit more tricky than just having more colors.
get_num_bins
gets called with n_classes
as well and it references NUM_BINS
which also only has 10 values.
What would be a good default value for NUM_BINS
for n_classes
> 10?
Any good ideas about having more colors? Just repeating the colors and giving a warning, or making up new colors?
Yeah, That's the problem. I started running out of ideas for colors and default values above 10. May be a sequential color map is required.
Currently running into the same issue for an idea I am testing. But totally understandable. Maybe a semi-simple and quick workaround is just to declare a simple target to color hex dict or just allowing us to passing in a list of colors.
As in the user declares the targets to color dict on their end.
{0: "#fcba03", 1: "#a303a9"}
Any solution? I even considered not using colors, but when I add None to the color_blind_friendly_colors array (colors.py), I get the following error: color_map = {v: color_values[i] for i, v in enumerate(class_values)}
TypeError: 'NoneType' object is not subscriptable
In principle, just add another list of colors so this works:
color_values = color_blind_friendly_colors[n_classes]
In principle, just add another list of colors so this works:
color_values = color_blind_friendly_colors[n_classes]
I have 30 classes. I don't really care about colors, they can all be represented by the same color. Can I make it work?
See if you can set dtreeviz.color_blind_friendly_colors[30+1] = [c]*30
for some color c
.
See if you can set
dtreeviz.color_blind_friendly_colors[30+1] = [c]*30
for some colorc
.
Worked, thanks :) Had to change the NUM_BINS array as well
Maybe allow to represent only certainty of the written class via the hue. Then you can either have hue="class_certainty" or hue="certainty", and it switches to hue="certainty" above 10 classes and probably drops a warning that it did.
Hi folks, if you still need a solution for this issue, you can follow this PR https://github.com/parrt/dtreeviz/pull/185
@tlapusan tla, @parrt
Hi, I really appreciate the work making support on more classes.
I now have a 86 classes decision tree model. Is it any possible way to call decision_boundaries
without color issue?( "Index Error")
Or It's a bad idea having 86 classes , should I make my classes smaller?