-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW4.py
37 lines (24 loc) · 972 Bytes
/
HW4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from SVM.SVM import *
import numpy as np
training = "Perceptron/bank-note/train.csv"
testing = "Perceptron/bank-note/test.csv"
C = [100/873, 500/873, 700/873]
for c in C:
d = 0.9
functor = lambda y0, t: y0 / ( 1 + t * y0 / d)
weights = primal_svm(training, 100, functor, c)
print("C=", c)
print("vector=", weights[1])
standardresult = test_primal(weights, training)
print("training =", 1 - standardresult[0]/standardresult[1])
standardresult = test_primal(weights, testing)
print("test =", 1 - standardresult[0]/standardresult[1])
for c in C:
functor = lambda y0, t: y0 / ( 1 + t )
weights = primal_svm(training, 100, functor, c)
print("C=", c)
print("vector=", weights[1])
standardresult = test_primal(weights, training)
print("training =", 1 - standardresult[0]/standardresult[1])
standardresult = test_primal(weights, testing)
print("test =", 1 - standardresult[0]/standardresult[1])