[R] Regarding SVM using R

Abbas R. Ali abbas4s at yahoo.com
Tue Sep 8 15:09:25 CEST 2009





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


      


More information about the R-help mailing list