my_knn_cv: K-nearest Neighbors Cross Validation Function

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function performs knn cross validation on a set of data.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

input data frame

cl

true class value of your training data

k_nn

integer representing the number of neighbors

k_cv

integer representing the number of folds

Value

list with the following elements: class: a vector of the predicted class y for all observations cv_err: a numeric with the cross-validation misclassification error

Examples

1
2
3
4
5
6
7
8
data <- my_penguins %>%
        tidyr::drop_na()
train_data <- data %>%
              dplyr::select(bill_length_mm, bill_depth_mm,
                     flipper_length_mm, body_mass_g)
target_class <- data$species

my_knn_cv(train_data, target_class, 1, 5)

laurenng/stat302Package documentation built on Dec. 21, 2021, 9:42 a.m.