====== The k-Nearest Neighbour Algorithm ======
Let the people around me decide who I am. FIXME
===== Animation =====
For each row of the test set, the $k$ nearest (in Euclidean distance) training set vectors are found, and the classification is decided by majority vote, with ties broken at random.
===== R code =====
library(animation)
oopt = ani.options(ani.height = 500, ani.width = 600, outdir = getwd(), nmax = 10,
interval = 2, title = "Demonstration for kNN Classification",
description = "For each row of the test set, the k nearest (in Euclidean
distance) training set vectors are found, and the classification is
decided by majority vote, with ties broken at random.")
ani.start()
par(mar = c(3, 3, 1, 0.5), mgp = c(1.5, 0.5, 0))
knn.ani()
ani.stop()
ani.options(oopt)
===== More Examples =====
Try the ''iris'' data here:
library(animation)
set.seed(11)
idx = sample(nrow(iris), 140)
trn = iris[idx, ]
tst = iris[-idx, ]
ani.options(interval = 0.5)
knn.ani(trn[, 1:2], tst[, 1:2], cl = trn$Species,
k = 30)