0

I have this code written in R for a knn loop. When I try to run it, it gives me the following error.

Something is wrong; all the Accuracy metric values are missing:

    Accuracy       Kappa    
 Min.   : NA   Min.   : NA  
 1st Qu.: NA   1st Qu.: NA  
 Median : NA   Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.: NA   3rd Qu.: NA  
 Max.   : NA   Max.   : NA  
 NA's   :3     NA's   :3    
library(caret)
i=1
k.opt=1
for (i in 1:28){ 
   ctrl_SMOTE=trainControl(method = "cv",number=i,savePredictions = T,classProbs = T,sampling = "smote")
   set.seed(123)
   knnFit_smote <- train(class~., data=train1, method="knn",trControl=ctrl_SMOTE)
   k=i  
   cat(k,'=',k.optm[i],'\n')       # to print % accuracy 
 }
knnFit_smote
plot(knnFit_smote, type="b", xlab="K- Value",ylab="Accuracy level")
confusionMatrix(knnFit_smote)

Here is the dput:

structure(list(checking_status = c(2, 4, 1, 2, 4, 1, 4, 4, 2, 4, 2, 2, 1, 4, 2, 2, 4, 2, 4, 2, 4, 2, 4, 1, 3, 1, 3, 4, 4, 2)),row.names = c(NA, -668L), class = "data.frame")
Matt
  • 7,255
  • 2
  • 12
  • 34
user13073332
  • 21
  • 1
  • 7
  • Hi there, it will be much easier if you provide at least a sample of your data, for example with `dput(train1)`. Please see [How to make a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more info. – Ian Campbell Apr 07 '20 at 17:57
  • Hi would this be enough structure(list(checking_status = c(2, 4, 1, 2, 4, 1, 4, 4, 2, 4, 2, 2, 1, 4, 2, 2, 4, 2, 4, 2, 4, 2, 4, 1, 3, 1, 3, 4, 4, 2)),row.names = c(NA, -668L), class = "data.frame") – user13073332 Apr 07 '20 at 18:20
  • is it true that the data you are trying to train has only one column? I don't think so, I see class is used inside train(...) – StupidWolf Apr 07 '20 at 21:15
  • Hello @StupidWolf and ian campbell thanks for the help i was able to figure it out i had an issue with my data=train1 as it was not correctly defined – user13073332 Apr 14 '20 at 19:11

0 Answers0