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

Crash when leaf nodes have no samples #305

Open
taltstidl opened this issue Sep 12, 2023 · 2 comments
Open

Crash when leaf nodes have no samples #305

taltstidl opened this issue Sep 12, 2023 · 2 comments

Comments

@taltstidl
Copy link

Thanks for the great library. The visualizations are truly great. However, we're running into a crash when some of the leaf nodes do not have any samples in the X_train and y_train data. What seems to happen is the following:

  • When calling render = viz_model.view() all necessary legend/node/leaf files are created. However, as some of the leaf nodes have no samples, the check in
    if sum(counts) == 0:
    comes into play and no .svg file is generated for that leaf.
  • Later when calling render.save('file.svg'), dot tries to render the SVG, but fails as the dot code returned by view still references the SVG files even though they were not created.

Two possible solutions to this:

  1. def _class_leaf_viz(node: ShadowDecTreeNode,
    Here, render an empty SVG or similar so it can later be rendered (this would be my preferred option).
  2. leaves.append(class_leaf_node(node))
    Here, do not add a leaf if no file could be created (would likely need to add a suitable return value to _class_leaf_viz).
@tlapusan
Copy link
Collaborator

Hi @taltstidl ,

Thanks for raising this issue. There was some work related to it but it wasn't done completely. ex. #299

I will take a look on it in the next days, it seems to be an issue also when the split nodes don't have samples.

@Crefok
Copy link

Crefok commented Oct 4, 2024

workaround:
if you use the Model Training Data to create the dtreeviz.model you should be finde. If you want to draw a sample or Test Data you can get this Messages like

Warning: No such file or directory while opening .../leafXXX_{pid}.svg
Error: No or improper image file=".../leafXXX_{pid}.svg"
in label of node leafXXX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants