knn

Purpose

Creates a K-nearest-neighbour classifier.

Synopsis


y = knn(xtrain, xtest, t, kmax)

Description

y = knn(xtrain, xtest, t, kmax) takes a matrix xtrain of input vectors (one vector per row) with corresponding 1-of-N coded class labels in the matrix t and uses the k-nearest-neighbour rule to produce a matrix y of classifications for a new input matrix xtest. The nearest neighbours are determined using Euclidean distance. The kth column of the matrix y contains the predicted class labels (as an index 1..N, not as 1-of-N coding) using k nearest neighbours, where k runs from 1 to kmax.

Example


y = knn(xtrain, xtest, targets, 2);
Puts in the first column of y the classification of each vector in xtest according to the nearest neighbour rule. The second column of y contains the classification of each vector according to the 2 nearest neighbour rule.

See Also

kmeans
Pages: Index

Copyright (c) Christopher M Bishop, Ian T Nabney (1996, 1997)