dtlearner.py - class DTLearner(object): def _init_(self,...

This preview shows page 1 - 2 out of 2 pages.

class DTLearner(object):def __init__(self, leaf_size, verbose = False):self.leaf_size = leaf_sizeself.max_depth = 100self.current_depth = 0pass # move along, these aren't the drones you're looking fordef get_best_split_corr(self, dataX, dataY):return np.argmax([np.abs(np.correlate(dataX[:,i], dataY)) for i inrange(dataX.shape[1])])def buildTree(self, dataX, dataY):if dataX.shape[0] == 0:return np.array([-1, 0, -1, -1])if len(set(dataY)) == 1:return [-1, dataY[0], -1, -1]if dataX.shape[0] <= self.leaf_size:if self.leaf_size != 1:return np.array([-1, np.mean(dataY), -1, -1])else:return np.array([-1, dataY[0], -1, -1])i = self.get_best_split_corr(dataX, dataY)# using median to make it as close to log base 2 height.# trying to keep the tree balanced.SplitVal = np.median(dataX[:, i])# comprehension, if it wereleft_split = [dataX[:,i]<=SplitVal]# grabem columnsright_split = [dataX[:,i]>SplitVal]if np.sum(left_split) == dataX[:,i].shape[0]:return np.array([-1, np.mean(dataY), -1, -1])lefttree = self.buildTree(dataX[left_split], dataY[left_split])righttree = self.buildTree(dataX[right_split], dataY[right_split])

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
Tucker Balch
Tags
Das Model, righttree, return np argmax

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture