示例#1
0
    print "Printing digit example #" + str(example_number + 1) + " with label: " \
        + str(ALL_TRAINING_LABELS[example_number])
    _print_digit_image(ALL_TRAINING_IMAGES[example_number])
    print

    for i in range(10, 11):
        # Calling the basic feature extractor
        features = mp.extract_basic_features(
            ALL_TRAINING_IMAGES[example_number], DATA_WIDTH, DATA_HEIGHT)

        # Compute parameters for a Naive Bayes classifier using the basic feature
        # extractor
        mp.compute_statistics(ALL_TRAINING_IMAGES,
                              ALL_TRAINING_LABELS,
                              DATA_WIDTH,
                              DATA_HEIGHT,
                              mp.extract_advanced_features,
                              percentage=10.0 * i,
                              k=.0001)

        # Making predictions on validation data
        predicted_labels = mp.classify(ALL_VALIDATION_IMAGES, DATA_WIDTH,
                                       DATA_HEIGHT,
                                       mp.extract_advanced_features)

        incorrect = []
        correct_count = 0.0
        for ei in range(len(predicted_labels)):
            if (ALL_VALIDATION_LABELS[ei] == predicted_labels[ei]):
                correct_count += 1
            else:
    # Calling the basic feature extractor
    features = mp.extract_basic_features(ALL_TRAINING_IMAGES[example_number],
                                         DATA_WIDTH, DATA_HEIGHT)
    #mp.extract_advanced_features(ALL_TRAINING_IMAGES[example_number],DATA_WIDTH, DATA_HEIGHT)
    #mp.extract_advanced_features(ALL_TRAINING_IMAGES[2075],DATA_WIDTH, DATA_HEIGHT)

    # Compute parameters for a Naive Bayes classifier using the basic feature
    # extractor
    #mp.compute_statistics(ALL_TRAINING_IMAGES, ALL_TRAINING_LABELS, DATA_WIDTH,DATA_HEIGHT, mp.extract_basic_features)

    # Making predictions on validation data
    #predicted_labels = mp.classify(ALL_VALIDATION_IMAGES, DATA_WIDTH, DATA_HEIGHT,mp.extract_basic_features)

    #with advance features
    #mp.compute_statistics(ALL_TRAINING_IMAGES, ALL_TRAINING_LABELS, DATA_WIDTH, DATA_HEIGHT, mp.extract_advanced_features)
    #predicted_labels = mp.classify(ALL_VALIDATION_IMAGES, DATA_WIDTH, DATA_HEIGHT, mp.extract_advanced_features)

    #with final features
    mp.compute_statistics(ALL_TRAINING_IMAGES, ALL_TRAINING_LABELS, DATA_WIDTH,
                          DATA_HEIGHT, mp.extract_final_features)
    predicted_labels = mp.classify(ALL_VALIDATION_IMAGES, DATA_WIDTH,
                                   DATA_HEIGHT, mp.extract_final_features)
    correct_count = 0.0
    for ei in range(len(predicted_labels)):
        if (ALL_VALIDATION_LABELS[ei] == predicted_labels[ei]):
            correct_count += 1

    print "Correct prediction: " + str(correct_count / len(predicted_labels))
    print("--- %s seconds ---" % (time.time() - start_time))
示例#3
0
    # Load all data
    _load_all_data()

    # Pring a random traning example
    example_number = random.randint(0, NUMBER_OF_TRAINING_EXAMPLES)
    print "Printing digit example #" + str(example_number + 1) + " with label: " \
        + str(ALL_TRAINING_LABELS[example_number])
    _print_digit_image(ALL_TRAINING_IMAGES[example_number])
    print

    # Calling the basic feature extractor
    features = mp.extract_basic_features(ALL_TRAINING_IMAGES[example_number],
                                         DATA_WIDTH, DATA_HEIGHT)

    # Compute parameters for a Naive Bayes classifier using the basic feature
    # extractor
    mp.compute_statistics(ALL_TRAINING_IMAGES, ALL_TRAINING_LABELS, DATA_WIDTH,
                          DATA_HEIGHT, mp.extract_basic_features, 100)

    # Making predictions on validation data
    predicted_labels = mp.classify(ALL_VALIDATION_IMAGES, DATA_WIDTH,
                                   DATA_HEIGHT, mp.extract_basic_features)

    correct_count = 0.0
    for ei in range(len(predicted_labels)):
        if (ALL_VALIDATION_LABELS[ei] == predicted_labels[ei]):
            correct_count += 1

    print "Correct prediction: " + str(correct_count / len(predicted_labels))