Description Usage Arguments Details Value Author(s) References See Also Examples

These functions are used to apply the generic train-and-test mechanism to a K-nearest neighbors (KNN) classifier.

1 2 | ```
learnKNN(data, status, params, pfun)
predictKNN(newdata, details, status, ...)
``` |

`data` |
The data matrix, with rows as features and columns as the samples to be classified. |

`status` |
A factor, with two levels, classifying the samples. The length must
equal the number of |

`params` |
A list of additional parameters used by the classifier; see Details. |

`pfun` |
The function used to make predictions on new data, using the trained classifier. |

`newdata` |
Another data matrix, with the same number of rows as |

`details` |
A list of additional parameters describing details about the particular classifier; see Details. |

`...` |
Optional extra parameters required by the generic "predict" method. |

The input arguments to both `learnKNN`

and `predictKNN`

are dictated by the requirements of the general train-and-test
mechanism provided by the `Modeler-class`

.

The implementation uses the `knn`

method from the
`class`

package. The `params`

argument to
`learnKNN`

must be alist that at least includes the component
`k`

that specifies the number of neighbors used.

The `learnKNN`

function returns an object of the
`FittedModel-class`

, logically representing a KNN
classifier that has been fitted on a training `data`

set.

The `predictKNN`

function returns a factor containing the
predictions of the model when applied to the new data set.

Kevin R. Coombes <krc@silicovore.com>

Ripley, B. D. (1996) *Pattern Recognition and Neural Networks*.
Cambridge.

Venables, W. N. and Ripley, B. D. (2002) *Modern Applied
Statistics with S*. Fourth edition. Springer.

See `Modeler-class`

and `Modeler`

for details
about how to train and test models. See
`FittedModel-class`

and `FittedModel`

for
details about the structure of the object returned by `learnPCALR`

.

1 2 3 4 5 6 7 8 9 10 11 12 13 | ```
# simulate some data
data <- matrix(rnorm(100*20), ncol=20)
status <- factor(rep(c("A", "B"), each=10))
# set up the parameter list
knn.params <- list(k=5)
# learn the model
fm <- learnKNN(data, status, knn.params, predictKNN)
# Make predictions on some new simulated data
newdata <- matrix(rnorm(100*30), ncol=30)
predictKNN(newdata, fm@details, status)
``` |

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.