Created
December 27, 2018 00:13
-
-
Save amaarora/04734ff0a04ef9bf5dee398a815c7c2c to your computer and use it in GitHub Desktop.
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
class TreeEnsemble(): | |
def __init__(self, x, y, n_trees, sample_sz, min_leaf=5): | |
np.random.seed(42) | |
self.x,self.y,self.sample_sz,self.min_leaf = x,y,sample_sz,min_leaf | |
self.trees = [self.create_tree() for i in range(n_trees)] | |
def create_tree(self): | |
rnd_idxs = np.random.permutation(len(self.y))[:self.sample_sz] | |
return DecisionTree(self.x.iloc[rnd_idxs], self.y[rnd_idxs], min_leaf=self.min_leaf) | |
def predict(self, x): | |
return np.mean([t.predict(x) for t in self.trees], axis=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment