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 -- 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
Hi Steve ? I am facing a little problem in predict function which is I think mismatch of dimension. Infacted area is covered by ***. ? svm = function() { ?library(RODBC)?????# load RODBC library for database access ?channel = odbcConnect("demo_dsn", "sa", "1234")??# connecting to the database with the dabtabase ?data = sqlQuery(channel, "SELECT top 100 * FROM [Demographics].[dbo].[CHA_Training]")? ?odbcClose(channel) ?????# close the database connection ?index = 1:nrow(data)?????# getting a vector of same size as data ?sample_index <- sample(index, length(index) / 3)??# samples of the above vector ??training <- data[-sample_index, ]????# 2/3 training data ??validation <- data[sample_index, ]???# 1/3 test data ?x = training[, length(training)]? ???# seperating class labels? ? ?model.ksvm = ksvm(x, data = training, kernel = "rbfdot", kpar= list(sigma = 0.05), C = 5, cross = 3)?# train data through SVM ?******************************************************************* ?Problamisitc area:? ?prSV = predict(model.ksvm, validation[, -length(validation)], type = "decision")???# validate data ?Error: Error in .local(object, ...) : test vector does not match model ! ?Notes: If I modified the predict function as "prSV = predict(model.ksvm, validation[, length(validation)], type = "decision")" ?then it works but its not correct. ?***************************************************************** ?table(prSV, validation[, length(validation)])???# draw table } ? ? ? Thanks ? Abbas
Hi, On Sep 8, 2009, at 9:56 AM, Abbas R. Ali wrote:> my dimentions of trining set dim(trainingset) = 7 x 96 and dim > (validation) = 3 x 96 > > other thing if i want to predicit trainingset accuracy it is also > giviing me same error. Now its no issue of dimentions from my side.1. Please keep replies on list 2 . Please post your new code along with the error. Thank, -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