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")