R studio SVM finding the optimal intercept given the coefficients of the hyperplane I want to know how to obtain the optimal intercept using support vector machines.
I have two classes of points normally distributed. I want to find the optimal c such that 2x1+x2=c separates the two classes of points.
The way I have done it is by applying the classification 2x1+x2 to all of the points in my data set and then finding the optimal hyperplane using SVM (e1071). However, I don't get the hyperplane in the form 2x1+x2 (The coefficients are different but the hyperplane is optimal).
Is there a way to input my own coefficients into R studio to obtain an optimal c(intercept)? In otherwords the value of c in wx=c that minimalizes the the classification error.
 A: The "vanilla" SVM algorithm does not allow for fixing the w coefficients (at least that I'm aware of). But, you could maybe project the data into the known coefficients, i.e. create $z=2x_1+x_2$, and run SVM on it. Extracting the intercept there seems to work in this toy example:
library(e1071)
x = matrix(rnorm(200, mean=1), ncol=2)
c = 2
y = factor(2*x[,1]+x[,2]- c >= 0)
plot(x, col=y)

z = 2*x[,1]+x[,2]

fit = svm(y~z, kernel="linear", cost=10, scale=F)
w = t(fit$SV) %*% fit$coefs
b = -fit$rho
intercept = -b/w[1]; intercept


[1] 1.938905

I think this should generalize to more than just 2D $x$'s. But you'd have to be more careful. Suppose the real separation plane is $2x_1+x_2-2x_3-2=0$ but you only know the coef. of $x_1$ and $x_2$:
# 3D
x = matrix(rnorm(300, mean=1), ncol=3)
c = 2
w = -2
y = factor(2*x[,1]+x[,2]+w*x[,3]-c>= 0)
z = 2*x[,1]+x[,2]
plot(z, x[,3], col=y)

fit = svm(y~z+x[,3], kernel="linear", cost=10, scale=F)
w = t(fit$SV) %*% fit$coefs
b = -fit$rho
intercept = -b/w[2]; intercept
slope = -w[1]/w[2]; slope

The intercept (~-1) and slope (~0.5) here are of the separation plane $\frac{1}{2}(2x_1+x_2)-x_3-1=0$.
