Learn R Programming

KODAMA (version 0.0.1)

KNN.CV: Cross-Validation with k-Nearest Neighbors Classifier.

Description

This is function performs a 10-fold cross validation on a given data set using k nearest neighbors (kNN) classifier. The output is a vector of predicted labels.

Usage

KNN.CV(x,cl,constrain,kn=10)

Arguments

x
a matrix.
cl
a classification vector.
constrain
a vector of nrow(data) elements. Sample with the same identificative constrain will be split in the training set or in the test test of cross-validation together.
kn
the number of nearest neighbors to consider.

Value

The function returns a vector of predicted labels.

Details

Details are described in Cover, et al. (1967).

References

Cover TM, Hart PE. TNearest neighbor pattern classification. IEEE Trans Inf Theory 1967;13(1):21-7.

See Also

PLS.SVM.CV,PCA.CA.KNN.CV

Examples

Run this code
data(iris)
u=iris[,-5]
class=as.factor(iris[,5])
results=KNN.CV(u,class,1:length(class))
levels(results)=levels(class)
table(results,class)

Run the code above in your browser using DataLab