JuliaAI / DecisionTree.jl

Julia implementation of Decision Tree (CART) and Random Forest algorithms
Other
356 stars 102 forks source link

Round thresholds in display of trees #197

Closed ablaom closed 1 year ago

ablaom commented 1 year ago

After wrapping a tree using DecisionTree.wrap(tree) I get:

julia> wt
Feature: 4 < 0.8
├─ Class: 1 (50/50)
└─ Feature: 4 < 1.75
   ├─ Feature: 3 < 4.95
   │  ├─ Feature: 4 < 1.65
   │  │  ├─ Class: 2 (47/47)
   │  │  └─ Class: 3 (1/1)
   │  └─ Feature: 4 < 1.55
   │     ├─ Class: 3 (3/3)
   │     └─ Feature: 3 < 5.449999999999999
   │        ├─ Class: 2 (2/2)
   │        └─ Class: 3 (1/1)
   └─ Feature: 3 < 4.85
      ├─ Feature: 2 < 3.1
      │  ├─ Class: 3 (2/2)
      │  └─ Class: 2 (1/1)
      └─ Class: 3 (43/43)

And using @roland-KA's plot recipe (WIP) we get:

image

I suggest that the thresholds get rounded using, say round(thresh, sigdigits=4).

roland-KA commented 1 year ago

That would indeed improve the display of the tree. The print_tree-function uses also a value of sigdigits = 4 when printing to the screen (2 otherwise). So this would fit. I could add that to printnode.

BTW: Could you publish the code leading to the decision tree above? It's also a good example, where the node rectangles are too small to fit the labels. So I could check, if adapting the values for width and height can solve the problem or if the plot recipe needs a bit more polish. You used the default values to create this plot, didn't you?

ablaom commented 1 year ago

I could add that to printnode.

❤️

Could you publish the code leading to the decision tree above?

Sorry, can't find it now, but I think it's iris with all default hyperparameters.