From: Van Kerckhoven, Johan <Johan.VanKerckhoven_at_econ.kuleuven.be>

Date: Mon 03 Jul 2006 - 16:52:44 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 03 17:06:56 2006

Date: Mon 03 Jul 2006 - 16:52:44 EST

Johan Van Kerckhoven

ORSTAT and University Center of Statistics
Katholieke Universiteit Leuven

#initialization 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)

#Extracting them directly from the model

yfit2 = svclass$fitted

#Display where predictions differ from each other

yfit != yfit2

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 03 17:06:56 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Mon 03 Jul 2006 - 18:15:01 EST.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*