| knn | R Documentation | 
This function applies knn algorithm to classify data.
knn(
  data,
  ClassLabel,
  p1,
  d_method = "euclidean",
  k,
  p = 3,
  learn = FALSE,
  waiting = TRUE
)
| 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  | 
| learn | Boolean value. If it is set to "TRUE" multiple clarifications and explanations are printed along the code | 
| waiting | If TRUE while  | 
Value of the new classified example.
Víctor Amador Padilla, victor.amador@edu.uah.es
# 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, learn = TRUE, waiting = FALSE)
knn(db_per_or,"y", c(1,1,1), "Hamming", 3, learn = TRUE, waiting = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.