thatisvivek
thatisvivek

Reputation: 915

Decision boundary calculation in SVM

I am unable to understand how decision boundary is calculated once we get the coefficients of the model.

Here is the link that I am referring: http://scikit-learn.org/stable/auto_examples/svm/plot_svm_margin.html

Here is the code

# get the separating hyperplane
w = clf.coef_[0]
a = -w[0] / w[1]
xx = np.linspace(-5, 5)
yy = a * xx - (clf.intercept_[0]) / w[1]

I didn't understand a = -w[0] / w[1] this line.

Why we are dividing one coefficient with another?

Upvotes: 2

Views: 1596

Answers (1)

Miriam Farber
Miriam Farber

Reputation: 19664

The separating hyperplane has the form w[0]*x+w[1]*y+intercept=0. So

w[1]*y=-w[0]*x-intercept

Now divide both sides by w[1], and you get

y=-(w[0]/w[1])*x-intercept/w[1].

This is exactly the equation that appears in your code.

Upvotes: 3

Related Questions