Reputation: 3
I am training a kNN model with train function from the R caret package and a dataset of 2000 entries. I used the following code:
set.seed(400)
ctrl <- trainControl(method="none")
knnFit <- train(Class ~ ., data = ScaniaTrain, method = "knn", trControl = ctrl, tuneLength = 1)
but the R keeps crashing. How can I improve the performance of this function?
Upvotes: 0
Views: 413
Reputation: 584
KNN is costly, it may not be possible to train a model if you have lots of columns in your data (or if you have lots of categorical variables that caret expands to dummy variables under the hood).
You can try to set the k
parameter to a low value and see if it works:
knnFit <- train(
Class ~ .,
data = ScaniaTrain,
method = "knn",
trControl = ctrl,
tuneGrid = c(k=3)
)
Upvotes: 1