[R] Regarding SVM using R

Steve Lianoglou mailinglist.honeypot at gmail.com
Sun Sep 6 03:35:40 CEST 2009

Hi Abbas,

Before I try to give you answers, I just want to mention that you
should send R related reqests to the R-help list, and not me
personally because (i) there's a greater likelihood that it will get
answered in a timely manner, and (ii) people who might have a similar
problem down the road might benefit from any answer via searching the
list archives ... anyway:

On Sep 5, 2009, at 1:41 PM, Abbas R. Ali wrote:

> Hi Steve
> I need your kind help on implementing SVM using R. I am previously applied neural network technique on the same data and want to get results from SVM as well.
> I have 2-D data and want to apply regression on it. After training and prediction I will pass it on my function model_metric(predicted, original, …) to plot the data as I have attached with this email. I want SVM training and prediction source code in R (regression) which can plot my data same as the attached figure.

Use the e1071 package and (i) look at the Example section in ?svm and
(ii) run it to see it work live. There is an example of running
running regression:

R> library(e1071)
R> ?svm
R> example(svm)

You'll see several plots pop up that are very similar to what you're
trying to do.

> On thing is that I have to read data directly from SQL server can you please tell me how can I separate target field from rest of the data (any R command which can separate last field of a matrix).

Figure out what type of database you need to query and get the
appropriate library to do so. Do you mean "sql server" as Microsoft's
SQLServer? Try RODBC, otherwise there's RSQLite, RPostgreSQL, and
RMySQL you can try if you're using those databases.

You can use those libraries to send a sql query to your database and
will be returned a data.frame of your results. You can manipulate that
data.frame in the usual way to pick off your "target" column from. the
predictor/feature columns and train your SVM accordingly (or use the
entire data.frame along with the formula invocation of SVM).

Hope that helps,

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