lau_knn
USE:
[class]=lau_knn(k,X,y,x)
DESCRIPTION:
Implements a k-nearest neighbor algorithm. This is a simple classification
rule which assigns for a new point x the class in which are found most of the k
nearest neighbors of x in the training data set.
ARGUMENTS:
X must be
an mxp matrix (p>=1) and y an m rows vector. y corresponds to the class variable while X with the feature
vector. Values of y must be integers from 1 to Nc (number of classes).
k is the
number of neighbors on which decision is taken.
x is a
matrix of size (nxp) of new samples which needs to be
classified. n>=1.
VALUES:
The
function returns class which is a column vector
indicating the class in which the elements of x matrix are classified.
EXAMPLES:
//load the
iris data set. There are 3 classes and 50 samples in each
> irisdata
//use half
of the iris data set as prototypes, for a 5-nearest neighbor, to classify the
remaining half
>class=lau_knn(5,X(1:2:end,:),y(1:2:end),X(2:2:end,:))
//computes
in how many of the 75 cases the classification was successful
> sum(class==y(2:2:end))
COMMENTS:
Created by Laurentiu Adi
Tarca. Revised 10.07.2003
This help
was created on 12.03.2004