Last active
February 15, 2020 08:11
-
-
Save kareem1925/d1d39867498c31c3a12f52fa9636997f to your computer and use it in GitHub Desktop.
plotting decision boundary of linear classifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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