Beispiel #1
0
def leave_one_out(examples,k):
    conf_matr = ConfusionMatrix()
    for ex in examples:
        # disable only this example
        ex.active = False
        # run the k-Nearest-Neighbor algorithm
        rank_list = knn.knn(k,examples,ex)
        # check the voting for correctness
        outcome = knn.voting(rank_list)
        conf_matr.inc_according_to(outcome,ex.outcome)
        ex.active = True
    # return the computed confusion matrix
    return conf_matr
def leave_one_out(examples, k):
    conf_matr = ConfusionMatrix()
    for ex in examples:
        # disable only this example
        ex.active = False
        # run the k-Nearest-Neighbor algorithm
        rank_list = knn.knn(k, examples, ex)
        # check the voting for correctness
        outcome = knn.voting(rank_list)
        conf_matr.inc_according_to(outcome, ex.outcome)
        ex.active = True
    # return the computed confusion matrix
    return conf_matr