NN1toKmaxPredict: NN1toKmaxPredict Algo

Description Usage Arguments Value Examples

Description

Coding Project 1 R function for NN1toKmaxPredict Algo

Usage

1
NN1toKmaxPredict(X.mat, Y.vec, testX.mat, max_neighbors)

Arguments

X.mat

numeric input feature matrix [n x p]

Y.vec

numeric input label vetor [n], either all 0/1 for bninary classification or other real numbers for regression, it doesn't support others

testX.mat

numeric test matrix

max_neighbors

scalar integer, max number of neighbors

Value

numeric vector size of n x max_neighbors, predictions from 1 to max_neighbors for all rows of testX.mat

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data(zip.train, package = "ElemStatLearn")
io1 <- which(zip.train[,1] %in% c(0,1))
train.i <- io1[1:5]
test.i <- io1[6:10]
X <- zip.train[train.i, -1]
Y <- zip.train[train.i, 1]
testX <- zip.train[test.i, -1]
max_neighbors <- 3
NN1toKmaxPredict(X,Y,testX, 3)

data(prostate, package = "ElemStatLearn")
io1 <- which(zip.train[,1] %in% c(0,1))
train.i <- io1[1:5]
test.i <- io1[6:10]
X <- zip.train[train.i, -1]
Y <- zip.train[train.i, 1]
testX <- zip.train[test.i, -1]
max_neighbors <- 3
NN1toKmaxPredict(X,Y,testX, 3)

mertayD/Coding_Project_1_NN documentation built on June 1, 2019, 3:57 a.m.