Caret and KNN in R: predict function gives error
问题 I try to predict with a simplified KNN model using the caret package in R. It always gives the same error, even in the very simple reproducible example here: library(caret) set.seed(1) #generate training dataset "a" n = 10000 a = matrix(rnorm(n*8,sd=1000000),nrow = n) y = round(runif(n)) a = cbind(y,a) a = as.data.frame(a) a[,1] = as.factor(a[,1]) colnames(a) = c("y",paste0("V",1:8)) #estimate simple KNN model ctrl <- trainControl(method="none",repeats = 1) knnFit <- train(y ~ ., data = a,