Beispiel #1
0
def random_concept(num_instances=1, num_objects=10):
    tree = TrestleTree()
    for i in range(num_instances):
        #print("Training concept with instance", i+1)
        inst = random_instance(num_objects)
        #pprint(inst)
        tree.ifit(inst)
    return tree.root
def random_concept(num_instances=1, num_objects=10):
    tree = TrestleTree()
    for i in range(num_instances):
        # print("Training concept with instance", i+1)
        inst = random_instance(num_objects)
        # pprint(inst)
        tree.ifit(inst)
    return tree.root
class ScikitTrestle(object):
    def __init__(self, params=None):
        if params is None:
            self.tree = TrestleTree()
        else:
            self.tree = TrestleTree(**params)

    def ifit(self, x, y):
        x = deepcopy(x)
        x['_y_label'] = "%i" % y
        self.tree.ifit(x)

    def fit(self, X, y):
        X = deepcopy(X)
        for i, x in enumerate(X):
            x['_y_label'] = "%i" % y[i]
        self.tree.fit(X, randomize_first=False)

    def predict(self, X):
        return [int(self.tree.categorize(x).predict('_y_label')) for x in X]
Beispiel #4
0
class ScikitTrestle(object):

    def __init__(self, **kwargs):
        self.tree = TrestleTree(**kwargs)
        self.state_format = "variablized_state"

    def ifit(self, x, y):
        x = deepcopy(x)
        x['_y_label'] = float(y)
        self.tree.ifit(x)

    def fit(self, X, y):
        X = deepcopy(X)
        for i, x in enumerate(X):
            x['_y_label'] = float(y)
        self.tree.fit(X, randomize_first=False)

    def skill_info(self, X):
        raise NotImplementedError("Not implemented Erik H. says there is a way \
             to serialize this -> TODO")

    def predict(self, X):
        return [self.tree.categorize(x).predict('_y_label') for x in X]