Trying to use knn, basic. but I'm clueless


New Member
Hi can someone please help me with this I don't know what's wrong and I went to my professor and he said he didn't know and that I should figure it out.

so I need to use a dataset called wine at

and then to use the k-nearest neighbor classifier with k=1 and k=5. and then classify the data into type 1 type 2 or type 3.

so what I did was...

-load the dataset called wine
-name the columns, with the first column being the type (this part was correct)
-> knn(wine, cl, k = 1, l = 0, prob = FALSE, use.all = TRUE)

but I am not really sure what the arguments mean. I read it at

but it just doesn't make sense.

and I thought that what I was supposed to do was just have one command with k=1 and then run it again with k=5

I also tried just stripping all the stuff I thought was useless and using the bare minimum
> knn(wine1, k = 1)
but I got this error...

Error in knn(wine1, k = 1) : unused argument(s) (k = 1)

If someone can please please help me, I would very much appreciate it.


New Member
ok so I changed my code to this but I still get an error....

> train <- rbind(wine1[1:10,], wine1[60:70,], wine1[131:141,])
> test<-rbind(wine1[11:59,],wine1[71:130,],wine1[142:178,])
> cl <- factor(c(rep("1",10), rep("2",70), rep("3",141)))
> knn(train,test,cl,k=1,prob=TRUE)
Error in knn(train, test, cl, k = 1, prob = TRUE) :
unused argument(s) (k = 1, prob = TRUE)