knn {LearnSL} | R Documentation |
K-Nearest Neighbors
Description
This function applies knn algorithm to classify data.
Usage
knn(
data,
ClassLabel,
p1,
d_method = "euclidean",
k,
p = 3,
details = FALSE,
waiting = TRUE
)
Arguments
data |
Data frame with already classified observations. Each column represents a parameter of the values. The last column contains the output, this means, the expected output when the other column values are inputs. Each row is a different observation. |
ClassLabel |
String containing the name of the column of the classes we want to classify |
p1 |
Vector containing the parameters of the new value that we want to classify. |
d_method |
String with the name of the distance method that will
be used. It must be one of |
k |
Number of closest values that will be considered in order to classify the new value ("p1"). |
p |
Exponent used in the |
details |
Boolean value. If it is set to "TRUE" multiple clarifications and explanations are printed along the code |
waiting |
If TRUE while |
Value
Value of the new classified example.
Author(s)
VĂctor Amador Padilla, victor.amador@edu.uah.es
Examples
# example code
knn(db_flowers,"ClassLabel", c(4.7, 1.2, 5.3, 2.1), "chebyshev", 4)
knn(db_flowers,"ClassLabel", c(4.7, 1.5, 5.3, 2.1), "chebyshev", 5)
knn(db_flowers,"ClassLabel", c(6.7, 1.5, 5.3, 2.1), "Euclidean", 2, details = TRUE, waiting = FALSE)
knn(db_per_or,"y", c(1,1,1), "Hamming", 3, details = TRUE, waiting = FALSE)