Hi! I created a knn model to classify a group of cities into two classes (1 and 0). The model worked, but I would like to know who are the closest neighbors for each example that was classified. I don't know how to do this. It´s possible to print the k closest neighbors for each exemple? Below is the code I used to classify the cities in the test group.
#-> code_coment
keep <- condense(data_train[, -(1:2)], class = data_train[,2])
for(i in 1:10){
set.seed(123456)
previsoes[[i]] <- knn(train = data_train[keep,-(1:2)], test= data_test[,-(1:2)],cl= data_train[keep,2],k=i)
perc.erro[i] <- mean(data_teste[,2] != previsoes[[i]] )
}
R_code <- here
After this loop, i´m going to use k=2.