[R] How to get w and b in SVR? (package e1071)

Steve Lianoglou mailinglist.honeypot at gmail.com
Mon Aug 3 15:59:40 CEST 2009


Hi Marlene,

On Aug 3, 2009, at 8:59 AM, marlene marchena wrote:

> Dear R users,
>
> I'm running a SVR in package e1071 but I did not able to calculate the
> parameters w and b of the regression. I don't know how to do that  
> and if it
> is possible to do it with this package.
>
> Someone have some idea. Any help would be much appreciated.

While you're not given the W vector directly, you can recover it from  
the support vectors, no? In LaTeX form, W looks like:

  \vec{W} = \sum_{i=1}^N \alpha_i y_i \vec{x}_i

If "model" was the object returned from your SVM: alpha_i's are the  
weights of each vector (model$coefs[i]) and x_i are the support  
vectors (model$SV[i,]).

You can use some matrix multiplication to calculate this very quickly:

W <- t(model$coefs) %*% model$SV

By default, the x's and y's are scaled when you call svm(..) so I  
think, by definition, your y intercept (b) should be zero. I think the  
values in model$y.scale might be what you're looking for, though (not  
sure).

Hope that helps,
-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list