@@ -28,6 +28,11 @@ apart from the two points mentioned.
28
28
In analogy to the type definitions of `DecisionTree`, the generic type `S` is
29
29
the type of the feature values used within a node as a threshold for the splits
30
30
between its children and `T` is the type of the classes given (these might be ids or labels).
31
+
32
+ !!! note
33
+ You may only add lacking class labels. It's not possible to overwrite existing labels
34
+ with this mechanism. In case you want add class labels, the generic type `T` must
35
+ be a subtype of `Integer`.
31
36
"""
32
37
struct InfoNode{S, T} <: AbstractTrees.AbstractNode{DecisionTree.Node{S,T}}
33
38
node :: DecisionTree.Node{S, T}
@@ -89,8 +94,8 @@ AbstractTrees.children(node::InfoNode) = (
89
94
AbstractTrees. children (node:: InfoLeaf ) = ()
90
95
91
96
"""
92
- printnode(io::IO, node::InfoNode)
93
- printnode(io::IO, leaf::InfoLeaf)
97
+ printnode(io::IO, node::InfoNode; sigdigits=4 )
98
+ printnode(io::IO, leaf::InfoLeaf; sigdigits=4 )
94
99
95
100
Write a printable representation of `node` or `leaf` to output-stream `io`.
96
101
@@ -108,23 +113,28 @@ For the condition of the form `feature < value` which gets printed in the `print
108
113
variant for `InfoNode`, the left subtree is the 'yes-branch' and the right subtree
109
114
accordingly the 'no-branch'. `AbstractTrees.print_tree` outputs the left subtree first
110
115
and then below the right subtree.
116
+
117
+ `value` gets rounded to `sigdigits` significant digits.
111
118
"""
112
- function AbstractTrees. printnode (io:: IO , node:: InfoNode )
119
+ function AbstractTrees. printnode (io:: IO , node:: InfoNode ; sigdigits= 4 )
120
+ featval = round (node. node. featval; sigdigits)
113
121
if :featurenames ∈ keys (node. info)
114
- print (io, node. info. featurenames[node. node. featid], " < " , node . node . featval)
122
+ print (io, node. info. featurenames[node. node. featid], " < " , featval)
115
123
else
116
- print (io, " Feature: " , node. node. featid, " < " , node . node . featval)
124
+ print (io, " Feature: " , node. node. featid, " < " , featval)
117
125
end
118
126
end
119
127
120
- function AbstractTrees. printnode (io:: IO , leaf:: InfoLeaf )
128
+ function AbstractTrees. printnode (io:: IO , leaf:: InfoLeaf ; sigdigits = 4 )
121
129
dt_leaf = leaf. leaf
122
130
matches = findall (dt_leaf. values .== dt_leaf. majority)
123
131
match_count = length (matches)
124
132
val_count = length (dt_leaf. values)
125
133
if :classlabels ∈ keys (leaf. info)
134
+ @assert dt_leaf. majority isa Integer " classes must be represented as Integers"
126
135
print (io, leaf. info. classlabels[dt_leaf. majority], " ($match_count /$val_count )" )
127
136
else
128
- print (io, " Class: " , dt_leaf. majority, " ($match_count /$val_count )" )
137
+ print (io, dt_leaf. majority isa Integer ? " Class: " : " " ,
138
+ dt_leaf. majority, " ($match_count /$val_count )" )
129
139
end
130
140
end
0 commit comments