Description Usage Arguments Value Examples
Run k-fold cross validations for k-nearest neighbors.
1 |
data |
The input data frame used for prediction. Note this data should not include NAs. |
cl |
The true class values of the data, which are compared against the KNN prediction. Note these classification should not include NAs. |
k_nn |
An integer that represents the number of neighbors KNN should use. |
k_cv |
The number of folds that the function will use for cross validation. |
A list containing the following items.
The vector class
, which contains the predicted classes when KNN train on the entire provided data set.
The number cv_err
, which is between 0 and 1 and shows the cross-validation misclassification rate.
1 2 3 4 5 6 7 8 9 10 11 12 13 | ## Load and set up the penguins data
data(my_penguins)
my_penguins <- na.omit(my_penguins)
penguins_no_NA <- na.omit(my_penguins)
my_data <- data.frame("bill_length" = penguins_no_NA$bill_length_mm,
"bill_depth" = penguins_no_NA$bill_depth_mm,
"flipper_length" = penguins_no_NA$flipper_length_mm,
"body_mass" = penguins_no_NA$body_mass_g)
my_cl <- penguins_no_NA$species
my_knn_cv(data = my_data, cl = my_cl, k_nn = 2, k_cv = 5)
my_knn_cv(data = my_data, cl = my_cl, k_nn = 7, k_cv = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.