print "=" * 10, "EPOCH", i + 1, "=" * 10

        # get the sets for training and testing
        training_set_names = set_names[:]
        test_set_names = [training_set_names.pop(i)]
        training_set = fileutils.get_data_set(features_save_path,
                                              training_set_names,
                                              dictionary_size)
        test_set = fileutils.get_data_set(features_save_path, test_set_names,
                                          dictionary_size)

        print "Training sets:", training_set_names
        print "Test set:", test_set_names

        # train and test
        p.train(training_set)
        p.test(test_set)
        (precision, recall, f1) = p.get_results()

        # prints the results and calc the avg results
        print_results(precision, recall, f1)
        avg_precision += precision / len(set_names)
        avg_recall += recall / len(set_names)
        avg_f1 += f1 / len(set_names)

        print ""

    print "=" * 10, "Average results", "=" * 10
    print_results(avg_precision, avg_recall, avg_f1)
Beispiel #2
0
def train_and_perception():
    p = Perception(2, f)
    input_vecs, labels = get_training_dataset()
    p.train(input_vecs, labels, 10, 0.1)
    return p