condense(train, class, store, trace=T)
The store set is used to 1-NN classify the rest, and misclassified patterns are added to the store set. The whole set is checked until no additions occur.
P. A. Devijver and J. Kittler (1982) Pattern Recognition. A Statistical Approach. Prentice-Hall, pp. 119-121.
train <- rbind(iris[1:25,,1],iris[1:25,,2],iris[1:25,,3]) test <- rbind(iris[26:50,,1],iris[26:50,,2],iris[26:50,,3]) cl <- factor(c(rep("s",25),rep("c",25), rep("v",25))) set.seed(99) keep <- condense(train, cl) knn(train[keep, , drop=F], test, cl[keep]) keep2 <- reduce.nn(train, keep, cl) knn(train[keep2, , drop=F], test, cl[keep2])