Suppose I want to fit a k-nearest-neighbour using
caret package in
library(caret) index <- createDataPartition(iris$Species, p=0.75, list=FALSE) iris_train <- iris[ index, ] iris_test <- iris[-index, ] fitControl <- trainControl(method = "cv", number = 4, savePred = TRUE, classProb = TRUE) iris_knn <- train(Species ~ ., data = iris_train, method = "knn", trControl = fitControl)
As far as I understand k-nn, this algorithm defines the class of an observation according to an election: the k closest points to the observation are considered the most frequent class is defined as the correct class for the observation.
Many sources I checked say that Euclidean distance is the most commonly used distance, but suppose I need another distance because of reasons. How can I define another distance using
For example, suppose I have evidence to say that Manhattan distance is better than Euclidean to my data set. How can I say this to