MCPcopy Index your code
hub / github.com/wepe/MachineLearning / plot_margin

Function plot_margin

SVM/SVM_by_QP/testSVM.py:58–84  ·  view source on GitHub ↗
(X1_train, X2_train, clf)

Source from the content-addressed store, hash-verified

56 return X_test, y_test
57
58def plot_margin(X1_train, X2_train, clf):
59 def f(x, w, b, c=0):
60 # given x, return y such that [x,y] in on the line
61 # w.x + b = c
62 return (-w[0] * x - b + c) / w[1]
63
64 pl.plot(X1_train[:,0], X1_train[:,1], "ro")
65 pl.plot(X2_train[:,0], X2_train[:,1], "bo")
66 pl.scatter(clf.sv[:,0], clf.sv[:,1], s=100, c="g")
67
68 # w.x + b = 0
69 a0 = -4; a1 = f(a0, clf.w, clf.b)
70 b0 = 4; b1 = f(b0, clf.w, clf.b)
71 pl.plot([a0,b0], [a1,b1], "k")
72
73 # w.x + b = 1
74 a0 = -4; a1 = f(a0, clf.w, clf.b, 1)
75 b0 = 4; b1 = f(b0, clf.w, clf.b, 1)
76 pl.plot([a0,b0], [a1,b1], "k--")
77
78 # w.x + b = -1
79 a0 = -4; a1 = f(a0, clf.w, clf.b, -1)
80 b0 = 4; b1 = f(b0, clf.w, clf.b, -1)
81 pl.plot([a0,b0], [a1,b1], "k--")
82
83 pl.axis("tight")
84 pl.show()
85
86def plot_contour(X1_train, X2_train, clf):
87 pl.plot(X1_train[:,0], X1_train[:,1], "ro")

Callers 1

test_linearFunction · 0.85

Calls 2

fFunction · 0.85
showMethod · 0.80

Tested by

no test coverage detected