train.knn: train.knn

Description Usage Arguments Value Note See Also Examples

View source: R/train.R

Description

Provides a wrapping function for the train.kknn.

Usage

1
2
3
4
train.knn(formula, data, kmax = 11, ks = NULL, distance = 2,
  kernel = "optimal", ykernel = NULL, scale = TRUE,
  contrasts = c(unordered = "contr.dummy", ordered = "contr.ordinal"),
  ...)

Arguments

formula

A formula object.

data

Matrix or data frame.

kmax

Maximum number of k, if ks is not specified.

ks

A vector specifying values of k. If not null, this takes precedence over kmax.

distance

Parameter of Minkowski distance.

kernel

Kernel to use. Possible choices are "rectangular" (which is standard unweighted knn), "triangular", "epanechnikov" (or beta(2,2)), "biweight" (or beta(3,3)), "triweight" (or beta(4,4)), "cos", "inv", "gaussian" and "optimal".

ykernel

Window width of an y-kernel, especially for prediction of ordinal classes.

scale

logical, scale variable to have equal sd.

contrasts

A vector containing the 'unordered' and 'ordered' contrasts to use.

...

Further arguments passed to or from other methods.

Value

A object knn.prmdt with additional information to the model that allows to homogenize the results.

Note

the parameter information was taken from the original function train.kknn.

See Also

The internal function is from package train.kknn.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data("iris")

n <- seq_len(nrow(iris))
.sample <- sample(n, length(n) * 0.75)
data.train <- iris[.sample,]
data.test <- iris[-.sample,]

modelo.knn <- train.knn(Species~., data.train)
modelo.knn
prob <- predict(modelo.knn, data.test, type = "prob")
prob
prediccion <- predict(modelo.knn, data.test, type = "class")
prediccion
confusion.matrix(data.test, prediccion)

PROMiDAT/trainR documentation built on Oct. 27, 2020, 8:33 p.m.