Skip to content

Instantly share code, notes, and snippets.

@kareem1925
Last active February 15, 2020 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kareem1925/d1d39867498c31c3a12f52fa9636997f to your computer and use it in GitHub Desktop.
Save kareem1925/d1d39867498c31c3a12f52fa9636997f to your computer and use it in GitHub Desktop.
plotting decision boundary of linear classifier
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
X = np.array([[-1,-2],[2,6],[-1.5,-2.8],[4,4],[-1,-9.6], [9,11]])
y = [0,1,0,1,0,1]
clf = svm.SVC(kernel='linear', C = 1.0,tol=1e-12,random_state=5)
clf.fit(X,y)
w = clf.coef_[0]
a = -w[0] / w[1]
xx = np.linspace(-10,12)
yy = a * xx - clf.intercept_[0] / w[1]
plt.plot(xx, yy, 'b-',label='decision boundary')
plt.scatter(X[:, 0], X[:, 1], c = y)
plt.legend()
plt.grid()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment