Displaying 1 result from an estimated 1 matches for "svclass".
Did you mean:
sclass
2006 Jul 03
0
Questions concerning function 'svm' in e1071 package
...itialization of the problem
rm(list=ls())
library(e1071)
set.seed(2)
n = 50
d = 4
p = 0.5
x = matrix(rnorm(n*d), ncol=d)
mushift = c(1, -1, rep(0, d-2))
y = runif(n) > p
y = factor(2*y - 1)
x = x - outer(rep(1, n), mushift)
x[y == 1, ] = x[y == 1] + 2*outer(rep(1, sum(y == 1)), mushift)
svclass = svm(x, y, scale=FALSE, kernel="linear")
#Computation of the weight vector
w = t(svclass$coefs) %*% svclass$SV
if (y[1] == -1) {
w = -w
}
#Derivation of predicted class lavels
#Using method in documentation
yfit = (x %*% t(w) + svclass$rho) > 0
yfit = factor(2*yfit - 1)
#Extra...