my_knn_cv: k-Nearest Neighbors Cross-Validation

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function splits the data into k groups for evaluating test set and training sets to predict the best value referring the neighbors.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Input data frame.

cl

True class value of your training data.

k_nn

Integer representing the number of neighbors.

k_cv

Integer representing the number of folds.

Value

A list consists of a vector class comprised of prediction made by knn() function from class package, and misclassification rate cv_err, a value between 0 and 1 representing the proportion of observations that were classified incorrectly.

Examples

1
2
3
4
penguins <- STAT302package::my_penguins
penguins2 <- na.omit(penguins)
my_cl <- penguins2 %>% dplyr::pull(species)
result_nn1 <- my_knn_cv(penguins2[, 3:6], my_cl, 1, 5)

samcho11/STAT302package documentation built on Dec. 22, 2021, 10:10 p.m.