Skip to content

Instantly share code, notes, and snippets.

@amaarora
Created December 27, 2018 00:58
Show Gist options
  • Save amaarora/92902654ccded7315d069eae895bb770 to your computer and use it in GitHub Desktop.
Save amaarora/92902654ccded7315d069eae895bb770 to your computer and use it in GitHub Desktop.
def find_better_split(self, var_idx):
x,y = self.x.values[self.idxs,var_idx], self.y[self.idxs]
for i in range(self.n):
lhs = x<=x[i]
rhs = x>x[i]
if rhs.sum()<self.min_leaf or lhs.sum()<self.min_leaf: continue
lhs_std = y[lhs].std()
rhs_std = y[rhs].std()
curr_score = lhs_std*lhs.sum() + rhs_std*rhs.sum()
if curr_score<self.score:
self.var_idx,self.score,self.split = var_idx,curr_score,x[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment