Description Usage Arguments Value Examples
Function performs cross validation to determine appropriate "k" for k-nearest-neighbors.
1 | my_knn_cv(train, cl, k_nn, k_cv)
|
train |
The dataset on which your model will be trained. |
cl |
The vector containing the actual classes of your observations. |
k_nn |
The number of nearest neighbors used to predict the class of an observation. |
k_cv |
The number of folds your training data will be divided into for cross-validation. |
A list containing vector "class", which contains the predicted classes using the entire data as training data, and the numeric "cv_err" which is the mean cross-validation error for your chosen "k".
1 2 3 4 | library(dplyr)
library(class)
my_knn_cv(my_penguins, my_penguins$species, 1, 5)
my_knn_cv(my_penguins, my_penguins$species, 5, 5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.