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.
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?