-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathml.py
40 lines (31 loc) · 758 Bytes
/
ml.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
34
35
36
37
38
39
40
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
from matplotlib import style
style.use("ggplot")
# x and y are seperated features
x = [1,5,1.5,8,1,9]
y = [2,8,1.8,8,0.6,11]
plt.scatter(x,y)
plt.show()
X = np.array([ [1,2],
[5,8],
[1.5,1.8],
[8,8],
[1,0.6],
[9,11]
])
y = [0,1,0,1,0,1]
clf = svm.SVC(kernel='linear',C = 1.0)
clf.fit(X,y)
print clf.predict([10.58,10.76])
# directional coefficient
w = clf.coef_[0]
print "coef: ", w
# learning rate a
a = -w[0] / w[1]
xx = np.linspace(0,12)
yy = a * xx - clf.intercept_[0] / w[1]
h0 = plt.plot(xx,yy,'k-', label="non weighted div")
plt.scatter(X[:,0],X[:,1], c = y)
plt.show()