示例#1
0
def test3():
    data = [Entry(id = None, correct = -1, features = np.array([1.0, 1.0])),
            Entry(id = None, correct = -1, features = np.array([-1.0, 1.0])),
            Entry(id = None, correct = -1, features = np.array([1.0, -1.0])),
            Entry(id = None, correct = -1, features = np.array([-1.0, -1.0])),
            Entry(id = None, correct = 1, features = np.array([5.0, 5.0])),
            Entry(id = None, correct = 1, features = np.array([-5.0, 5.0])),
            Entry(id = None, correct = 1, features = np.array([5.0, -5.0])),
            Entry(id = None, correct = 1, features = np.array([-5.0, -5.0]))]

    classifier = train_svm(data, 100.0, lambda x, y: kernels.poly2(x, y, 0.0))
    test_ans = test_svm(data, classifier)
    results = calculate_results(data, test_ans)
    print(results)
示例#2
0
def test3():
    data = [
        Entry(id=None, correct=-1, features=np.array([1.0, 1.0])),
        Entry(id=None, correct=-1, features=np.array([-1.0, 1.0])),
        Entry(id=None, correct=-1, features=np.array([1.0, -1.0])),
        Entry(id=None, correct=-1, features=np.array([-1.0, -1.0])),
        Entry(id=None, correct=1, features=np.array([5.0, 5.0])),
        Entry(id=None, correct=1, features=np.array([-5.0, 5.0])),
        Entry(id=None, correct=1, features=np.array([5.0, -5.0])),
        Entry(id=None, correct=1, features=np.array([-5.0, -5.0]))
    ]

    classifier = train_svm(data, 100.0, lambda x, y: kernels.poly2(x, y, 0.0))
    test_ans = test_svm(data, classifier)
    results = calculate_results(data, test_ans)
    print(results)
示例#3
0
文件: main.py 项目: karlicoss/ml-2013
    results = calculate_results(test_set, test_ans)

    err_rate = error_rate(results)
    prec = precision(results)
    rec = recall(results)
    f1 = f1score(results)
    if verbose:
        print("C = {}, test set error rate = {}".format(bestC, err_rate))

    return (classifier, err_rate, prec, rec, f1)


random.seed(6346)  # uncomment to make the program deterministic

ks = [(kernels.identity, "Identity kernel"),
      (lambda x, y: kernels.poly2(x, y, 0.0), "Homogeneous polynomial kernel")(
          lambda x, y: kernels.gaussian(x, y, -0.00001),
          "Gaussian kernel, gamma = -0.00001")]

for phi, desc in ks:
    cnt = 2
    serr = 0.0
    sprec = 0.0
    srec = 0.0
    sf1 = 0.0
    print("--------------------------------")
    print("Running {} iterations using {}".format(cnt, desc))

    for i in range(cnt):
        stderr.write("Running... {}/{}\n".format(i, cnt))
        _, err_rate, prec, rec, f1 = run_all(data, phi, verbose=True)
示例#4
0
文件: main.py 项目: rybak/ml-2013
    err_rate = error_rate(results)
    prec = precision(results)
    rec = recall(results)
    f1 = f1score(results)
    if verbose:
        print("C = {}, test set error rate = {}".format(bestC, err_rate))

    return (classifier, err_rate, prec, rec, f1)


random.seed(6346)  # uncomment to make the program deterministic

ks = [
    (kernels.identity, "Identity kernel"),
    (lambda x, y: kernels.poly2(x, y, 0.0), "Homogeneous polynomial kernel")(
        lambda x, y: kernels.gaussian(x, y, -0.00001), "Gaussian kernel, gamma = -0.00001"
    ),
]

for phi, desc in ks:
    cnt = 2
    serr = 0.0
    sprec = 0.0
    srec = 0.0
    sf1 = 0.0
    print("--------------------------------")
    print("Running {} iterations using {}".format(cnt, desc))

    for i in range(cnt):
        stderr.write("Running... {}/{}\n".format(i, cnt))