[R] Regarding SVM using R

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Sep 8 15:19:27 CEST 2009


Hi,

On Sep 8, 2009, at 9:09 AM, Abbas R. Ali wrote:

> 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

You need to pass in data of the same dimension (# of cols) that you  
trained on to your predict function.

You have already split your data into training and testing  
(`training`, `validation`). Why are you removing certain dimensions  
(features/columns) from your validation set when you pass it into the  
predict function? ie:

predict(model.ksvm, validation[, -length(validation)]

should probably be

predict(model.ksvm, validation, ...)

That should work ... but if you're using this for anything serious, be  
sure you understand why.

-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