[R] Regarding SVM using R

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Sep 8 15:51:52 CEST 2009


Hi,

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

> by using predict(model.ksvm, validationset, ...) I am facing  
> following error:
>
> "Error: '...' used in an incorrect context"

No. I didn't mean to explicitly use "...", sorry.

Actually, I had a two line fix here, but I'm looking back at your  
original code, now it seems there's more of a problem. Note that the  
data you pass to `ksvm` and `predict` should be similar!

Presumably you are passing in a matrix of n observations with m  
features. The matrix should be of dimension n x m!

The matrix for training needs to have m columns, as does the matrix  
for predict. Look at your original code and notice that you are  
removing columns from your `training` and `validation` sets ... WHY?

Here are relevant pieces of your code:

training <- data[-sample_index, ]    # 2/3 training data
validation <- data[sample_index, ]   # 1/3 test data
# So far so good
x = training[, length(training)]
# Why are you removing the columns? The columns are the features
# for each example, aren't they? All examples need to have the same
# number of features!

# ...
prSV = predict(model.ksvm, validation[, -length(validation)], type =  
"decision")
# Notice that you are now removing A DIFFERENT column in the test
# set. Does it make sense to remove some random FEATURE in training
# and another completely different feature from testing? No, it probably
# doesn't.

In short -- stop removing the features (columns) from your training/ 
testing data and it should work.

-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