The k-Nearest Neighbour Algorithm

Let the people around me decide who I am. FIXME

Animation

Demonstration for kNN Classification
loading animation frames... 0%

For each row of the test set, the \normalsize 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)
 
dmml/k-nearest_neighbour_algorithm.txt · Last modified: 2009/01/07 00:08 by 218.107.132.124
 
Recent changes RSS feed Creative Commons License Donate to AniWiki Contribute Your Ideas! Driven by DokuWiki