# knn.reg: k Nearest Neighbor Regression

## Description

k-nearest neighbor regression

## Usage

knn.reg(train, test = NULL, y, k = 3, algorithm=c("kd_tree",
"cover_tree", "brute"))

## Arguments

train

matrix or data frame of training set cases.

test

matrix or data frame of test set cases. A vector will be interpreted
as a row vector for a single case. If not supplied, cross-validataion will be done.

y

reponse of each observation in the training set.

k

number of neighbours considered.

algorithm

nearest neighbor search algorithm.

## Value

`knn.reg`

returns an object of `class`

`"knnReg"`

or `"knnRegCV"`

if `test`

data is not supplied.

The returnedobject is a list containing at least the following components:

callthe match call.

knumber of neighbours considered.

nnumber of predicted values, either equals test size or train size.

preda vector of predicted values.

residualspredicted residuals. `NULL`

if `test`

is supplied.

PRESSthe sums of squares of the predicted residuals. `NULL`

if `test`

is supplied.

R2Predpredicted R-square. `NULL`

if `test`

is supplied.

## Details

If test is not supplied, Leave one out cross-validation is performed and *R-square* is the predicted R-square.

## Examples

# NOT RUN {
if(require(chemometrics)){
data(PAC);
pac.knn<- knn.reg(PAC$X, y=PAC$y, k=3);
plot(PAC$y, pac.knn$pred, xlab="y", ylab=expression(hat(y)))
}
# }