[R] Predict function for 'newdata' of different dimension in svm

mcbride at duke.edu mcbride at duke.edu
Fri Mar 31 00:20:36 CEST 2006

I am using the "predict" function on a support vector machine (svm)
object, and I don't understand why I can't predict on a dataset with more
observations than the training dataset.

I think this problem is a generic "predict" problem, but I'm not sure.

The original svm was fit on 50 observations.


## for these training data,
> names(boot.dist.dat)
[1] "TOF"   "EXT"   "Acode"
> dim(boot.dist.dat)
[1] 50  3

Now I want to use the svm classifier on a new dataset with 175


## for the new dataset,
> names(new.dat)
[1] "TOF"   "EXT"   "Acode"
> dim(new.dat)
[1] 175   3

Now try to predict:

> predict(cd1.svm,newdata=new.dat)

Error in "names<-.default"(`*tmp*`, value = c("1", "2", "3", "4", "5",  :
        'names' attribute [175] must be the same length as the vector [50]

What am I missing?  Why would the row names have to be the same?

Thanks so much,
Sandra McBride


Sandra McBride
Research Scientist
Nicholas School of the Environment and
                Earth Sciences (NSEES)
Box 90328 Duke University
Levine Science Research Center
Durham, NC 27708-0328
(919) 622 3663

More information about the R-help mailing list