Skip to content

Commit 2e69696

Browse files
committed
Corrected decison trees leaf nodes
1 parent bc48e0b commit 2e69696

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

converters/decison_tree_converter.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ def get_tree_as_dict(self, clf):
3535
normalized_value = tree.value[node_id][0]
3636
if(normalized_value.shape[0] > 1):
3737
normalized_value = normalized_value / np.sum(normalized_value)
38+
feature = tree.feature[node_id]
39+
(left, right, threshold) = (tree.children_left[node_id], tree.children_right[node_id], tree.threshold[node_id])
40+
if(feature == -2):
41+
feature = None
42+
(left, right, threshold) = (None, None, None)
3843
nodes["node_" + node_id_str ] = {
39-
"left" : tree.children_left[node_id],
40-
"right" : tree.children_right[node_id],
41-
"feature" : tree.feature[node_id],
42-
"threshold" : tree.threshold[node_id],
44+
"left" : left,
45+
"right" : right,
46+
"feature" : feature,
47+
"threshold" : threshold,
4348
"impurity" : tree.impurity[node_id],
4449
"n_samples" : tree.n_node_samples[node_id],
4550
"w_samples" : tree.weighted_n_node_samples[node_id],

0 commit comments

Comments
 (0)