예제 #1
0
def construct_boosted_tree(training):
    weights = map(lambda x: 1.0 / len(training), training)
    decisionTrees = []
    for roundIdx in range(0, NUMBER_OF_ROUNDS):
        weights_sum = sum(weights)
        weights = map(lambda weight: weight / weights_sum, weights)
        tree = dt.construct_tree(weighted_bootstrap_set(training, weights))
        error = 0.0
        for i in range(0, len(training)):
            example = training[i]
            if example.promoter != dt.classify_sequence(tree, example.sequence):
                error += weights[i]
        if error > .5:
            return decisionTrees
        beta = error / (1 - error)
        for i in range(0, len(training)):
            example = training[i]
            if example.promoter == dt.classify_sequence(tree, example.sequence):
                weights[i] = weights[i] * beta
        decisionTrees.append((tree, beta))
    return decisionTrees
예제 #2
0
def construct_ensemble(sampling_number, training):
    ensemble = []
    for i in range(0, sampling_number):
        ensemble.append(dt.construct_tree(bootstrap_set(training)))
    return ensemble