1

I am running a Multiclass SVM on 1-Dimensional data. The SVM appears to be working properly, and I would now like to extract the decision boundaries that it found. My question is similar to a previous one, which has an incorrect and incomplete answer.

Classifier Code w/ Simple Data

#Data
X = np.asarray([[1, 1], [2, 1], [3, 1], [4, 1], [5, 1], [9, 1]]) #The Y Coordinates here are meaningless
Labels = [1, 1, 2, 2, 3, 3]

#Classifier
svc = svm.SVC(kernel='linear').fit(X, Labels)

Plotting Code

#Meshgrid for Contour Plot
x_min, x_max = np.min(X) - 1, np.max(X) + 1
y_min, y_max = 0, 2
h = .02  # step size in the mesh    
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                 np.arange(y_min, y_max, h))


# Draw Contour Plot
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)

# Plot training points
plt.scatter(X[:, 0], X[:, 1], cmap=plt.cm.Paired)
plt.xlabel('Signal')
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.yticks(()); #Y value is meaningless in this data. 

Multiclass SVM Plot

Coefficients

clf.coef_ is:

[[-1.          0.        ]
 [-0.66666667  0.        ]
 [-1.          0.        ]]

Intercepts

and clf.intercept_ is:

[ 2.5         2.33333333  4.5       ]

So now, how do I get the decision boundaries? In 2D, this is what I've seen done:

2D Algorithm for Boundary Extraction

Given the weights

W = svc.coef_
I = svc.intercept_

Then, I believe that we get our decision boundary via

y = a * x - b

Where

a = -W[0]/W[1]
b = I[0]/W[1]

However, this does not work for the data in question, because W[1] == 0 for all coefficient pairs.

How can I get these boundaries?

Alex Hall
  • 171
  • 11
  • not every line can be expressed as y = a*x-b, this is why we have **canonical** form ax + by + c = 0, and this is the equation you should use – lejlot Jun 21 '16 at 22:18
  • Thanks, and yes that makes sense. In fact, given that my data is 1D, it _should_ just be the the intercepts that matter. For the test data provided, the first and third intercept (2.5 and 4.5) are the correct decision boundaries, but I'm unclear on how I would know that it's those two values and to ignore the second value returned by svc.intercept_. The data I'm actually working with is more complex. – Alex Hall Jun 22 '16 at 19:16

0 Answers0