mywnn: Weighted Nearest Neighbor Classifier

Description Usage Arguments Value Author(s) Examples

View source: R/mywnn.R

Description

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

Usage

1
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.

Author(s)

Wei Sun, Xingye Qiao, and Guang Cheng

Examples

1
2
3
4
5
6
7
8
	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)

snn documentation built on May 1, 2019, 7:05 p.m.