====== 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)
saveHTML({ani.options( nmax = 10, interval = 2)
    par(mar = c(3, 3, 1, 0.5), mgp = c(1.5, 0.5, 0))
    knn.ani()
},
    img.name="knn_ani",htmlfile="knn_ani.html",
	ani.height = 500, ani.width = 600,
	title = "Demonstration for kNN Classification",
    description = c("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."))
===== 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)