R: Cross-Validation with k-Nearest Neighbors Classifier.
KNN.CV
R Documentation
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.
Details
Details are described in Cover, et al. (1967).
Value
The function returns a vector of predicted labels.
Author(s)
Stefano Cacciatore and Leonardo Tenori
References
Cover TM, Hart PE.
TNearest neighbor pattern classification. IEEE Trans Inf Theory 1967;13(1):21-7.
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(KODAMA)
Loading required package: e1071
Loading required package: plsgenomics
Loading required package: MASS
Loading required package: boot
Loading required package: parallel
Loading required package: class
Attaching package: 'KODAMA'
The following object is masked from 'package:plsgenomics':
transformy
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/KODAMA/KNN.CV.Rd_%03d_medium.png", width=480, height=480)
> ### Name: KNN.CV
> ### Title: Cross-Validation with k-Nearest Neighbors Classifier.
> ### Aliases: KNN.CV
> ### Keywords: croos-validation
>
> ### ** Examples
>
> 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)
class
results setosa versicolor virginica
setosa 50 0 0
versicolor 0 47 3
virginica 0 3 47
>
>
>
>
>
> dev.off()
null device
1
>