Learn R Programming

fdm2id (version 1.0.1)

KNN: Classification using k-NN

Description

This function builds a classification model using Logistic Regression.

Usage

KNN(
  train,
  labels,
  k = 1:10,
  nfolds = 10,
  tune = FALSE,
  methodparameters = NULL,
  graph = FALSE,
  seed = NULL,
  ...
)

Value

The classification model.

Arguments

train

The training set (description), as a data.frame.

labels

Class labels of the training set (vector or factor).

k

The k parameter.

nfolds

The number of folds of the cross-validation a method runs to choose its hyperparameters. Only used when there is something to choose, i.e. when one of them is given as a vector. Lower it to fit faster, at the cost of a noisier choice.

tune

If true, the function returns parameters instead of a classification model.

methodparameters

Present for interface consistency with performance (which always passes it when fitting a model). Currently unused: KNN does not support reusing pre-tuned parameters (it stores the training set and re-tunes k on every call when k is a vector).

graph

Present for interface consistency with performance (which always passes it when fitting a model). Currently unused: KNN does not produce a plot.

seed

A specified seed for random number generation, so that two runs on the same data give the same model. Every learning method accepts it, so that it can be set the same way whatever the method; the deterministic ones simply have nothing to draw and give the same model with or without it.

...

Other parameters.

See Also

Examples

Run this code
require (datasets)
data (iris)
KNN (iris [, -5], iris [, 5])

Run the code above in your browser using DataLab