my_knn_cv: k-nearest neighbors with cross validation

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

Builds a classification model for data train using the k-nearest neighbors algorithm with k = k_nn and applies k-fold cross-validation with k = k_cv.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Data frame used for training the model.

cl

Vector of true classifications for entries in train.

k_nn

Integer indicating how many neighbors should be considered in the k-nearest neighbors algorithm.

k_cv

Integer indicating how many folds train will be divided into for k-fold cross-validation. Must have k_cv >= 2.

Value

A list containing a vector of classifications predicted by the model using train as both the training data and the testing data and a numeric representing the cross-validation error from the k-fold cross-validation.

Examples

1
2
3
4
train <- na.omit(my_penguins)[,3:6]
cl <- na.omit(my_penguins)[1]
my_knn_cv(train, cl, 1, 5)
my_knn_cv(train, cl, 5, 5)

seangrimm/PROJECT3PACKAGE documentation built on March 22, 2021, 1:52 p.m.