Learn R Programming

snn (version 1.1)

mywnn: Weighted Nearest Neighbor Classifier

Description

Implement the weighted nearest neighbor classification algorithm to predict the label of a new input using a training data set.

Usage

mywnn(train, test, weight)

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.
weight
The weight vector for all n nearest neighbors.

Value

It returns the predicted class label of the new test point.

Examples

Run this code

	set.seed(1)
	n = 100
	d = 10
	DATA = mydata(n, d)

	## weighted nearest neighbor classifier
	weight.vec = c(rep(0.02,50), rep(0,50))
	mywnn(DATA, rep(-5,d), weight = weight.vec)

Run the code above in your browser using DataLab