-
-
Save monkey-codes/cc4dfeab7650d6cfd23417f49b488577 to your computer and use it in GitHub Desktop.
Simple implementation of finding the best split when building a tree for a random forest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_better_split(self, var_idx): | |
| x,y = self.x.values[self.idxs,var_idx], self.y[self.idxs] | |
| for i in range(1,self.n-1): | |
| lhs = x<=x[i] | |
| rhs = x>x[i] | |
| if rhs.sum()==0: 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