Exemple #1
0
a = AdaBoost(train = False)

for i in range(0, len(tmp), 4):

    alpha, demention, label, threshold = None, None, None, None

    for j in range(i, i + 4):
        if (j % 4) == 0:
            alpha = float(tmp[j])
        elif (j % 4) == 1:
            demention = int(tmp[j])
        elif (j % 4) == 2:
            label = float(tmp[j])
        elif (j % 4) == 3:
            threshold = float(tmp[j])

    classifier = a.Weaker(train = False)
    classifier.constructor(demention, label, threshold)
    a.G[i/4] = classifier
    a.alpha[i/4] = alpha
    a.N += 1

print "Construction finished"
fileObj.close()

output = a.prediction(Original_Data)

print numpy.count_nonzero(output[0:TESTING_POSITIVE_SAMPLE] > 0) * 1./ TESTING_POSITIVE_SAMPLE

print numpy.count_nonzero(output[TESTING_POSITIVE_SAMPLE:TESTING_SAMPLE_NUM] < 0) * 1./ TESTING_NEGATIVE_SAMPLE
Exemple #2
0
for i in range(0, len(tmp), 4):

    alpha, demention, label, threshold = None, None, None, None

    for j in range(i, i + 4):
        if (j % 4) == 0:
            alpha = float(tmp[j])
        elif (j % 4) == 1:
            demention = int(tmp[j])
        elif (j % 4) == 2:
            label = float(tmp[j])
        elif (j % 4) == 3:
            threshold = float(tmp[j])

    classifier = a.Weaker(train=False)
    classifier.constructor(demention, label, threshold)
    a.G[i / 4] = classifier
    a.alpha[i / 4] = alpha
    a.N += 1

print "Construction finished"
fileObj.close()

output = a.prediction(Original_Data)

print numpy.count_nonzero(
    output[0:TESTING_POSITIVE_SAMPLE] > 0) * 1. / TESTING_POSITIVE_SAMPLE

print numpy.count_nonzero(output[TESTING_POSITIVE_SAMPLE:TESTING_SAMPLE_NUM] <
                          0) * 1. / TESTING_NEGATIVE_SAMPLE
Exemple #3
0
for i in range(len(Tag)):
    if Tag[i] == 1:
        pyplot.plot(Original_Data[0][i], Original_Data[1][i], \
                    '+r', markersize = 10)
    else:
        pyplot.plot(Original_Data[0][i], Original_Data[1][i], \
                    '+b', markersize = 10)

a = AdaBoost(Original_Data, Tag)

a.train(100)

TestCase = [[0.55, 1.1, 5.35, 7.0, 8.5, -1.0, 3.0, 3.0, 4.0, 2, 3],
            [4.4, 2.8, 0.9, -12, -13, -9, -10, -9, -5, 0, 2.5]]

output = a.prediction(TestCase)

for i in range(len(output)):
    if output[i] == 1:
        pyplot.plot(TestCase[0][i], TestCase[1][i], \
                    'or', markersize = 20)
    else:
        pyplot.plot(TestCase[0][i], TestCase[1][i], \
                    'ob', markersize = 20)

pyplot.show()
"""
Demo Two
"""
Original_Data = numpy.array([[0], [1], [2], [3], [4], [5], [6], [7], [8],
                             [9]]).transpose()
        [+1],
        [+1],
        [+1],
    ]
).transpose()

Tag = Tag.flatten()

for i in range(len(Tag)):
    if Tag[i] == 1:
        pyplot.plot(Original_Data[0][i], Original_Data[1][i], "+r", markersize=10)
    else:
        pyplot.plot(Original_Data[0][i], Original_Data[1][i], "+b", markersize=10)


a = AdaBoost(Original_Data, Tag)

a.train(100)

TestCase = [[0.55, 1.1, 5.35], [4.4, 2.8, 0.9]]

output = a.prediction(TestCase)

for i in range(len(output)):
    if output[i] == 1:
        pyplot.plot(TestCase[0][i], TestCase[1][i], "or", markersize=20)
    else:
        pyplot.plot(TestCase[0][i], TestCase[1][i], "ob", markersize=20)

pyplot.show()