k-nearest neighbor regression

1 |

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

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

`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:

`call` |
the match call. |

`k` |
number of neighbours considered. |

`n` |
number of predicted values, either equals test size or train size. |

`pred` |
a vector of predicted values. |

`residuals` |
predicted residuals. |

`PRESS` |
the sums of squares of the predicted residuals. |

`R2Pred` |
predicted R-square. |

The code for “VR” nearest neighbor searching is taken from `class`

source

Shengqiao Li. To report any bugs or suggestions please email: shli@stat.wvu.edu.

`knn`

.

1 2 3 4 5 6 |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.