my_knn_cv: k-Nearest Neighbors Cross-Validation function

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function does Cross-Validation k-Nearest Neighbors prediction.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

The training data frame.

cl

A vector of true class value of train.

k_nn

An int representing the number of neighbors in knn.

k_cv

An int representing the number of folds in cv.

Value

A list of predicted classes class and, the mean rate of cross-validation misclassification error cv-err.

Examples

1
2
3
4
5
train <- na.omit(my_penguins) %>% dplyr::select(body_mass_g, bill_length_mm,
                                                bill_depth_mm,
                                                flipper_length_mm)
cl <- na.omit(my_penguins) %>% dplyr::select(species)
my_knn_cv(train, cl, 5, 5)

Ranul-Liu/STAT302package documentation built on Dec. 18, 2021, 9:52 a.m.