61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
import numpy as np
|
|
|
|
|
|
class DTLearner(object):
|
|
|
|
LEAF = -1
|
|
NA = -1
|
|
|
|
def __init__(self, leaf_size = 1, verbose = False):
|
|
self.leaf_size = leaf_size
|
|
self.verbose = verbose
|
|
|
|
def author(self):
|
|
return 'felixm' # replace tb34 with your Georgia Tech username
|
|
|
|
def create_node(self, factor: int, split: int, left: int, right: int):
|
|
return np.array((factor, split, left, right))
|
|
|
|
|
|
def build_tree(self, xs, y):
|
|
assert(xs.shape[0] == y.shape[0])
|
|
assert(xs.shape[0] > 0) # If this is 0 something went wrong.
|
|
|
|
if xs.shape[0] == 1:
|
|
return self.create_node(self.LEAF, y[0], self.NA, self.NA)
|
|
|
|
if np.all(y[0] == y):
|
|
return self.create_node(self.LEAV, y[0], self.NA, self.NA)
|
|
|
|
# XXX: continue here
|
|
y = np.array([y])
|
|
correlations = np.corrcoef(xs, y, rowvar=True)
|
|
print(f"{correlations=}")
|
|
|
|
return 0
|
|
|
|
def addEvidence(self, data_x, data_y):
|
|
"""
|
|
@summary: Add training data to learner
|
|
@param dataX: X values of data to add
|
|
@param dataY: the Y training values
|
|
"""
|
|
if self.verbose:
|
|
print(data_x)
|
|
print(data_y)
|
|
self.tree = self.build_tree(data_x, data_y)
|
|
|
|
|
|
|
|
def query(self,points):
|
|
"""
|
|
@summary: Estimate a set of test points given the model we built.
|
|
@param points: should be a numpy array with each row corresponding to a specific query.
|
|
@returns the estimated values according to the saved model.
|
|
"""
|
|
return
|
|
# return (self.model_coefs[:-1] * points).sum(axis = 1) + self.model_coefs[-1]
|
|
|
|
if __name__=="__main__":
|
|
print("the secret clue is 'zzyzx'")
|