@@ -209,7 +209,9 @@ cdef class Criterion:
209209 return (- self .weighted_n_right * impurity_right
210210 - self .weighted_n_left * impurity_left)
211211
212- cdef double impurity_improvement(self , double impurity) nogil:
212+ cdef double impurity_improvement(self , float64_t impurity_parent,
213+ float64_t impurity_left,
214+ float64_t impurity_right) nogil:
213215 """ Compute the improvement in impurity
214216 This method computes the improvement in impurity when a split occurs.
215217 The weighted impurity improvement equation is the following:
@@ -218,22 +220,24 @@ cdef class Criterion:
218220 where N is the total number of samples, N_t is the number of samples
219221 at the current node, N_t_L is the number of samples in the left child,
220222 and N_t_R is the number of samples in the right child,
223+
221224 Parameters
222225 ----------
223- impurity : double
224- The initial impurity of the node before the split
226+ impurity_parent : float64_t
227+ The initial impurity of the parent node before the split
228+
229+ impurity_left : float64_t
230+ The impurity of the left child
231+
232+ impurity_right : float64_t
233+ The impurity of the right child
234+
225235 Return
226236 ------
227237 double : improvement in impurity after the split occurs
228238 """
229-
230- cdef double impurity_left
231- cdef double impurity_right
232-
233- self .children_impurity(& impurity_left, & impurity_right)
234-
235239 return ((self .weighted_n_node_samples / self .weighted_n_samples) *
236- (impurity - (self .weighted_n_right /
240+ (impurity_parent - (self .weighted_n_right /
237241 self .weighted_n_node_samples * impurity_right)
238242 - (self .weighted_n_left /
239243 self .weighted_n_node_samples * impurity_left)))
0 commit comments