Created
December 8, 2017 03:19
-
-
Save groverpr/5e9d371a29687859adba31ee7e2cc159 to your computer and use it in GitHub Desktop.
code to find best split based on standard error
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
| xi = x # initialization of input | |
| yi = y # initialization of target | |
| # x,y --> use where no need to change original y | |
| ei = 0 # initialization of error | |
| n = len(yi) # number of rows | |
| predf = 0 # initial prediction 0 | |
| for i in range(30): # loop will make 30 trees (n_estimators). | |
| tree = DecisionTree(xi,yi) # DecisionTree scratch code can be found in shared github/kaggle link. | |
| # It just create a single decision tree with provided min. sample leaf | |
| tree.find_better_split(0) # For selected input variable, this splits (<n and >n) data so that std. deviation of | |
| # target variable in both splits is minimum as compared to all other splits | |
| r = np.where(xi == tree.split)[0][0] # finds index where this best split occurs | |
| left_idx = np.where(xi <= tree.split)[0] # index lhs of split | |
| right_idx = np.where(xi > tree.split)[0] # index rhs of split |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which decion tree library is used.I am confused