0
$\begingroup$

I'm following along https://rpubs.com/Drmadhu/IRISclassification to understand Knn classification. Here's the code I have: library(FNN)

iris.sample<-sample.int(n=nrow(irisdat),size=floor(0.75*nrow(irisdat)),replace=F)

set.seed(1)

iris.train<-irisdat[iris.sample,]

iris.test<-irisdat[-iris.sample,]

iristrain.labels<-iris.train$Species

iristest.labels<-iris.test$Species

iris.train1<-iris.train[-5]

iris.test1<-iris.test[-5]

iristest.pred<-knn(train=iris.train1,test=iris.test1,cl=iristrain.labels,k=3)

confmat1=as.matrix(table(Actual=iristest.labels,Predicted=iristest.pred))

acc1=(sum(diag(confmat1)))/sum(confmat1)

acc1

This gives me an acc1 value of 1, with the CrossTable as attached. What am I implementing incorrectly?

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.