RE: [R] KNN one factor predicting problem

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Wed 16 Mar 2005 - 00:05:36 EST


> From: liu qin
>
> Could anybody help me out please?
>
> > cl<-as.factor(traindata[,13])
> > knn(traindata[1:295,2], newdata[1:32,2], cl,k=2,
> prob=TRUE)
> Error in knn(traindata[1:295, 2], newdata[1:32, 2],
> cl, k = m, prob = TRUE) :
> Dims of test and train differ
>
> Both traindata and newdata have 13 elements. Only one
> of the first 12 elemnets is needed to predict the 13
> element.
> What's the problem of following commands?

`traindata[1:295, 2]' says to use the first 295 rows of the second column of traindata, and likewise you specified the first 32 rows of the second column of newdata as the second argument. What do you mean by 12 elements?

Andy  

> Thank you very much indeed
>
> Qin
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 16 00:09:11 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:47 EST