Learn R Programming

MachineShop (version 3.5.0)

KNNModel: Weighted k-Nearest Neighbor Model

Description

Fit a k-nearest neighbor model for which the k nearest training set vectors (according to Minkowski distance) are found for each row of the test set, and prediction is done via the maximum of summed kernel densities.

Usage

KNNModel(
  k = 7,
  distance = 2,
  scale = TRUE,
  kernel = c("optimal", "biweight", "cos", "epanechnikov", "gaussian", "inv", "rank",
    "rectangular", "triangular", "triweight")
)

Value

MLModel class object.

Arguments

k

numer of neigbors considered.

distance

Minkowski distance parameter.

scale

logical indicating whether to scale predictors to have equal standard deviations.

kernel

kernel to use.

Details

Response types:

factor, numeric, ordinal

Automatic tuning of grid parameters:

k, distance*, kernel*

* excluded from grids by default

Further model details can be found in the source link below.

See Also

kknn, fit, resample

Examples

Run this code
# \donttest{
## Requires prior installation of suggested package kknn to run

fit(Species ~ ., data = iris, model = KNNModel)
# }

Run the code above in your browser using DataLab