sknn

0th

Percentile

Simple k nearest Neighbours

Function for simple knn classification.

Keywords
classif
Usage
sknn(x, ...)# S3 method for default
sknn(x, grouping, kn = 3, gamma=0, ...)
# S3 method for data.frame
sknn(x, ...)
# S3 method for matrix
sknn(x, grouping, ..., subset, na.action = na.fail)
# S3 method for formula
sknn(formula, data = NULL, ..., subset, na.action = na.fail)
Arguments
x

matrix or data frame containing the explanatory variables (required, if formula is not given).

grouping

factor specifying the class for each observation (required, if formula is not given).

formula

formula of the form groups ~ x1 + x2 + .... That is, the response is the grouping factor and the right hand side specifies the (non-factor) discriminators.

data

Data frame from which variables specified in formula are preferentially to be taken.

kn

Number of nearest neighbours to use.

gamma

gamma parameter for rbf in knn. If gamma=0 ordinary knn classification is used.

subset

An index vector specifying the cases to be used in the training sample. (Note: If given, this argument must be named.)

na.action

specify the action to be taken if NAs are found. The default action is for the procedure to fail. An alternative is na.omit, which leads to rejection of cases with missing values on any required variable. (Note: If given, this argument must be named.)

...

currently unused

Details

If gamma>0 an gaussian like density is used to weight the classes of the kn nearest neighbors. weight=exp(-gamma*distance). This is similar to an rbf kernel. If the distances are large it may be useful to scale the data first.

Value

A list containing the function call.

predict.sknn, knn

Aliases
• sknn
• sknn.default
• sknn.formula
• sknn.matrix
• sknn.data.frame
Examples
# NOT RUN {
data(iris)
x <- sknn(Species ~ ., data = iris)
x <- sknn(Species ~ ., gamma = 4, data = iris)
# }

Documentation reproduced from package klaR, version 0.6-14, License: GPL-2

Community examples

Looks like there are no examples yet.