@@ -28,6 +28,11 @@ apart from the two points mentioned.
2828In analogy to the type definitions of `DecisionTree`, the generic type `S` is
2929the type of the feature values used within a node as a threshold for the splits
3030between 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`.
3136"""
3237struct InfoNode{S, T} <: AbstractTrees.AbstractNode{DecisionTree.Node{S,T}}
3338 node :: DecisionTree.Node{S, T}
@@ -89,8 +94,8 @@ AbstractTrees.children(node::InfoNode) = (
8994AbstractTrees. children (node:: InfoLeaf ) = ()
9095
9196"""
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 )
9499
95100Write a printable representation of `node` or `leaf` to output-stream `io`.
96101
@@ -108,23 +113,28 @@ For the condition of the form `feature < value` which gets printed in the `print
108113variant for `InfoNode`, the left subtree is the 'yes-branch' and the right subtree
109114accordingly the 'no-branch'. `AbstractTrees.print_tree` outputs the left subtree first
110115and then below the right subtree.
116+
117+ `value` gets rounded to `sigdigits` significant digits.
111118"""
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)
113121 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)
115123 else
116- print (io, " Feature: " , node. node. featid, " < " , node . node . featval)
124+ print (io, " Feature: " , node. node. featid, " < " , featval)
117125 end
118126end
119127
120- function AbstractTrees. printnode (io:: IO , leaf:: InfoLeaf )
128+ function AbstractTrees. printnode (io:: IO , leaf:: InfoLeaf ; sigdigits = 4 )
121129 dt_leaf = leaf. leaf
122130 matches = findall (dt_leaf. values .== dt_leaf. majority)
123131 match_count = length (matches)
124132 val_count = length (dt_leaf. values)
125133 if :classlabels ∈ keys (leaf. info)
134+ @assert dt_leaf. majority isa Integer " classes must be represented as Integers"
126135 print (io, leaf. info. classlabels[dt_leaf. majority], " ($match_count /$val_count )" )
127136 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 )" )
129139 end
130140end
0 commit comments