mybnn {snn} | R Documentation |
Bagged Nearest Neighbor Classifier
Description
Implement the bagged nearest neighbor classification algorithm to predict the label of a new input using a training data set.
Usage
mybnn(train, test, ratio)
Arguments
train |
Matrix of training data sets. An n by (d+1) matrix, where n is the sample size and d is the dimension. The last column is the class label. |
test |
Vector of a test point. It also admits a matrix input with each row representing a new test point. |
ratio |
Resampling ratio. |
Details
The bagged nearest neighbor classifier is asymptotically equivalent to a weighted nearest neighbor classifier with the i-th weight a function of the resampling ratio, the sample size n, and i. See Hall and Samworth (2005) for details. The tuning parameter ratio can be tuned via cross-validation, see cv.tune function for the tuning procedure.
Value
It returns the predicted class label of the new test point. If input is a matrix, it returns a vector which contains the predicted class labels of all the new test points.
Author(s)
Wei Sun, Xingye Qiao, and Guang Cheng
References
Hall, P. and Samworth, R. (2005). Properties of Bagged Nearest Neighbor Classifiers. Journal of the Royal Statistical Society, Series B, 67, 363-379.
Examples
# Training data
set.seed(1)
n = 100
d = 10
DATA = mydata(n, d)
# Testing data
set.seed(2015)
ntest = 100
TEST = mydata(ntest, d)
TEST.x = TEST[,1:d]
# bagged nearest neighbor classifier
mybnn(DATA, TEST.x, ratio = 0.5)