Model KNN: error unused arguments

Hi everybody!

I write a KNN model and my script is:

library(class)
library(ggplot2)
library(gmodels)
library(scales)
library(caret)
library(tidyverse)

db_data <- iris
row_train <- sample(nrow(iris), nrow(iris)*0.8)
db_train <- iris[row_train,]
db_test <- iris[-row_train,]

unique(db_train$Species)
table(db_train$Species)

#KNN
#-------
model_knn<-train(Species ~ ., data = db_train, method = "knn",tuneGrid = data.frame(k = c(2:20)))
summary(model_knn)
#-------

#PREDICTION NEW RECORD
#-------
test_data <- db_test
db_test$predict <- predict(model_knn, newdata=test_data, interval='confidence')
confusionMatrix(data=factor(db_test$predict),reference=factor(db_test$Species))
#-------

but when I run the model_knn I have this error:

Error in train(Species ~ ., data = db_train, method = "knn", tuneGrid = data.frame(k = c(2:20))) : 
  unused arguments (data = db_train, method = "knn", tuneGrid = data.frame(k = c(2:20)))

I can't understand why, since it was working perfectly until yesterday.
Can anyone tell me why I have this error today? How can I fix it?

Thanks

Is your session clear when you try this, or could you be maintaining state from old code or old sessions ?
what do you see when you do :

getAnywhere(train)

I tried closing and reopening the session and now it seems to work

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.