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 k-nearest neighbors cross-validation.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Input data frame to be trained.

cl

Vector of true class value of the training data.

k_nn

Numeric input representing number of neighbors.

k_cv

Numeric input representing number of folds.

Value

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

Examples

1
2
3
4
train <- rbind(iris3[, , 1], iris3[, , 2], iris3[, , 3])
cl <- factor(c(rep("s", 50), rep("c", 50), rep("v", 50)))
my_knn_cv(train, cl, k_nn = 1, k_cv = 5)
my_knn_cv(train, cl, k_nn = 5, k_cv = 5)

wanyeehing/project3package documentation built on Dec. 23, 2021, 5:07 p.m.