# NOT RUN {
# Using the example from the function knn.
library(class)
data(iris3)
train <- rbind(iris3[1:25,,1], iris3[1:25,,2], iris3[1:25,,3])
test <- rbind(iris3[26:50,,1], iris3[26:50,,2], iris3[26:50,,3])
cl <- c(rep(2, 25), rep(1, 25), rep(1, 25))
knn.out <- knn(train, test, as.factor(cl), k = 3, use.all = FALSE)
gknn.out <- gknn(train, cl, test, nn = 3)
# Both applications lead to the same predictions.
knn.out == gknn.out
# But gknn allows to use other distance measures than the Euclidean
# distance. E.g., the Manhattan distance.
gknn(train, cl, test, nn = 3, distance = "manhattan")
# }
Run the code above in your browser using DataLab