my_knn_cv: K-Nearest Neighbors Cross-Validation

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function does the Cross Validation test for the kth nearest neighbor predict model.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Data frame input that record X variable.

cl

Vector input of true class value of training data.

k_nn,

Numeric input representing the number of neighbors.

k_cv,

Numeric input representing the number of folds.

Value

a list includes class, a vector of the predicted class y-hat for all observations, cv_err, a numeric of the cross-validation misclassification error.

Examples

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

Chaos-Gao/MyStat302Package documentation built on March 20, 2021, 2 p.m.