my_knn_cv: K-nearest-neighbors cross-validation function

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

Predicts the class of the input data using k-nearest-neighbors and performs cross-validation to determine the misclassification error of the model.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Data frame input of training data.

cl

Vector input of true class values for the training data.

k_nn

Integer representing the number of neighbors.

k_cv

Integer representing the number of folds.

Value

List including a vector of class predictions for all observations and a numeric with the cross-validation misclassification error.

Examples

1
2
3
4
penguins <- my_penguins %>% tidyr::drop_na()
train <- penguins[,3:6]
cl <- penguins[,1]
my_knn_cv(train, cl, 1, 5)

marcradke/StatsTools documentation built on Dec. 21, 2021, 1:51 p.m.