#NEWLINE# def _update_terminal_region( self , tree , terminal_regions , leaf , X , y , residual , pred , sample_weight ) : #NEWLINE# #INDENT# 'Make a single Newton-Raphson step.\n\n        our node estimate is given by:\n\n            sum(w * (y - prob)) / sum(w * prob * (1 - prob))\n\n        we take advantage that: y - prob = residual\n        ' #NEWLINE# terminal_region = np . where ( ( terminal_regions == leaf ) ) [ 0 ] #NEWLINE# residual = residual . take ( terminal_region , axis = 0 ) #NEWLINE# y = y . take ( terminal_region , axis = 0 ) #NEWLINE# sample_weight = sample_weight . take ( terminal_region , axis = 0 ) #NEWLINE# numerator = np . sum ( ( sample_weight * residual ) ) #NEWLINE# denominator = np . sum ( ( ( sample_weight * ( y - residual ) ) * ( ( 1 - y ) + residual ) ) ) #NEWLINE# if ( denominator == 0.0 ) : #NEWLINE# #INDENT# tree . value [ ( leaf , 0 , 0 ) ] = 0.0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tree . value [ ( leaf , 0 , 0 ) ] = ( numerator / tree )