Description Usage Arguments Value Examples
Coding Project 1 R function for NN1toKmaxPredict Algo
1 | NN1toKmaxPredict(X.mat, Y.vec, testX.mat, max_neighbors)
|
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 |
numeric vector size of n x max_neighbors, predictions from 1 to max_neighbors for all rows of testX.mat
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.