train.knn | R Documentation |
Provides a wrapping function for the train.kknn
.
train.knn( formula, data, kmax = 11, ks = NULL, distance = 2, kernel = "optimal", ykernel = NULL, scale = TRUE, contrasts = c(unordered = "contr.dummy", ordered = "contr.ordinal"), ... )
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. |
A object knn.prmdt with additional information to the model that allows to homogenize the results.
the parameter information was taken from the original function train.kknn
.
The internal function is from package train.kknn
.
# Classification 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 # Regression len <- nrow(swiss) sampl <- sample(x = 1:len,size = len*0.20,replace = FALSE) ttesting <- swiss[sampl,] ttraining <- swiss[-sampl,] model.knn <- train.knn(Infant.Mortality~.,ttraining) prediction <- predict(model.knn, ttesting) prediction
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.