Exemplo n.º 1
0
def test_negative_contents():
    contents = load_positive_contents()
    cfy = Classify(500, 0.99, 0.2, 0.05)
    cfy.train(contents)

    contents = load_negative_contents()
    r = cfy.predict(contents)
    r = map(int, r)
    print(r.count(-1), r.count(1))
Exemplo n.º 2
0
def test_predict():
    contents = load_positive_contents()
    cfy = Classify(feature_num=10)
    cfy.train(contents)

    contents = load_negative_contents()
    cs = [contents.next() for i in range(10)]
    r = cfy.predict(cs)
    print(r)
Exemplo n.º 3
0
def test_save_load():
    contents = load_positive_contents()
    cfy = Classify(500, 0.99, 0.2, 0.05)
    cfy.train(contents)

    contents = load_negative_contents()
    cs = [contents.next() for i in range(10)]
    r = cfy.predict(cs)

    path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'save')
    cfy.save(path)

    cfy1 = load_cfy(path)
    r1 = cfy1.predict(cs)
    for i in range(10):
        if r[i] != r1[i]:
            print("save load error, got different svm")