@@ -623,7 +623,7 @@ cdef class BaseTree:
623
623
624
624
cdef DTYPE_t _compute_feature(self , const DTYPE_t[:, :] X_ndarray,
625
625
SIZE_t sample_index,
626
- Node * node, SIZE_t node_id ) nogil:
626
+ Node * node) nogil:
627
627
""" Compute feature from a given data matrix, X.
628
628
629
629
In axis-aligned trees, this is simply the value in the column of X
@@ -725,29 +725,23 @@ cdef class BaseTree:
725
725
cdef Node* node = NULL
726
726
cdef SIZE_t i = 0
727
727
728
- # to keep track of the current ID of each node
729
- cdef SIZE_t node_id = 0
730
-
731
728
# the feature value
732
729
cdef DTYPE_t feature_value = 0
733
730
734
731
with nogil:
735
732
for i in range (n_samples):
736
733
node = self .nodes
737
- node_id = 0
738
734
739
735
# While node not a leaf
740
736
while node.left_child != _TREE_LEAF:
741
737
# ... and node.right_child != _TREE_LEAF:
742
738
743
739
# compute the feature value to compare against threshold
744
- feature_value = self ._compute_feature(X_ndarray, i, node, node_id )
740
+ feature_value = self ._compute_feature(X_ndarray, i, node)
745
741
if feature_value <= node.threshold:
746
- node_id = node.left_child
747
- node = & self .nodes[node_id]
742
+ node = & self .nodes[node.left_child]
748
743
else :
749
- node_id = node.right_child
750
- node = & self .nodes[node_id]
744
+ node = & self .nodes[node.right_child]
751
745
752
746
out_ptr[i] = < SIZE_t> (node - self .nodes) # node offset
753
747
return out
@@ -861,9 +855,6 @@ cdef class BaseTree:
861
855
cdef Node* node = NULL
862
856
cdef SIZE_t i = 0
863
857
864
- # to keep track of the current ID of each node
865
- cdef SIZE_t node_id = 0
866
-
867
858
# the feature index
868
859
cdef DOUBLE_t feature
869
860
@@ -879,12 +870,10 @@ cdef class BaseTree:
879
870
indptr_ptr[i + 1 ] += 1
880
871
881
872
# compute the feature value to compare against threshold
882
- feature = self ._compute_feature(X_ndarray, i, node, node_id )
873
+ feature = self ._compute_feature(X_ndarray, i, node)
883
874
if feature <= node.threshold:
884
- node_id = node.left_child
885
875
node = & self .nodes[node.left_child]
886
876
else :
887
- node_id = node.right_child
888
877
node = & self .nodes[node.right_child]
889
878
890
879
# Add the leave node
@@ -1030,20 +1019,14 @@ cdef class BaseTree:
1030
1019
importances = np.zeros((self .n_features,))
1031
1020
cdef DOUBLE_t* importance_data = < DOUBLE_t* > importances.data
1032
1021
1033
- # to keep track of the current ID of each node
1034
- cdef SIZE_t node_id = 0
1035
-
1036
1022
with nogil:
1037
- node_id = 0
1038
-
1039
1023
while node != end_node:
1040
1024
if node.left_child != _TREE_LEAF:
1041
1025
# ... and node.right_child != _TREE_LEAF:
1042
1026
self ._compute_feature_importances(
1043
- importance_data, node, node_id )
1027
+ importance_data, node)
1044
1028
1045
1029
node += 1
1046
- node_id += 1
1047
1030
1048
1031
importances /= nodes[0 ].weighted_n_node_samples
1049
1032
@@ -1057,7 +1040,7 @@ cdef class BaseTree:
1057
1040
return importances
1058
1041
1059
1042
cdef void _compute_feature_importances(self , DOUBLE_t* importance_data,
1060
- Node* node, SIZE_t node_id ) nogil:
1043
+ Node* node) nogil:
1061
1044
""" Compute feature importances from a Node in the Tree.
1062
1045
1063
1046
Wrapped in a private function to allow subclassing that
0 commit comments