コード例 #1
0
ファイル: test.py プロジェクト: anton-bannykh/ml-2013
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))