0

I am trying to use k-fold validation to find the better k for kNN. But while I run the following code, it appeared error of "Wrong model type for classification". I had referred to the previous similar question ("Wrong model type for classification" in regression problems in R-Caret) but still can't figure out what is the mistake I made for my code.
The data classes are 11 quantitative, 13 quantitative variables (incl. 1 responding variable named:"classification")

install.packages("caret")
library(caret)
control <- trainControl(method="cv",number = 10)
model <- train(classification ~ .,data = CKD.train, method = "knn", trControl = control)
print(model)
文子小
  • 13
  • 4

1 Answers1

0

By quantitative do you mean continuous , and by qualitative do you mean categorical?

Because of the wording, I'm not sure if you're trying to predict a categorical response (classification) or a continuous response (regression).

Can you give an example of your data?

This issue is often solved by converting the data into a data.frame before you try and run train e.g.

CKD.train <- data.frame(CKD.train)
rw2
  • 1,549
  • 1
  • 11
  • 20
  • the CKD data is data frame. The qualitative means categorical and quantitative means continuous. I am predicting a categorical response. – 文子小 Mar 08 '22 at 23:25
  • This problem's normally caused by the data being in tibble format, rather than data.frame. If that's not the issue, have you checked that your response (it seems to be called `classification`?) is a factor? It's difficult to help any more without you providing a sample of your data, and telling us what format each column is in. What does `str(CKD.train)` output? – rw2 Mar 09 '22 at 10:24