my_knn_cv: K-nearest Neighbors Cross-validation Function

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function is used to predict a class using the k-nearest neighbors algorithm

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Data frame of covariate values used to predict a class

cl

String indicating the output class to predict

k_nn

Numeric for the number of neighbors to use in the k-nearest neighbors algorithm

k_cv

Numeric for the number of folds for cross-validation

Value

list with the cross-validation error and a vector of the predicted class

Examples

1
2
my_knn_cv(my_penguins[complete.cases(my_penguins), c(1, 3:6)], "species", 5, 5)
my_knn_cv(my_penguins[complete.cases(my_penguins), c(1, 3:5)], "species", 10, 10)

irenshaw99/stat302package documentation built on Dec. 20, 2021, 7:59 p.m.