my_knn_cv: k-Nearest Neighbors Cross-Validation Function

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function perform Cross-Validation k-Nearest Neighbors Cross-Validation.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

The training input data frame.

cl

True class value of train.

k_nn

Integer representing the number of neighbors.

k_cv

Integer representing the number of folds.

Value

A list of predicted class and a numeric with the cross-validation misclassification error cv-err.

Examples

1
2
3
4
5
6
data_cleaned <- na.omit(my_penguins)

data_train <- data_cleaned[, c("bill_length_mm", "bill_depth_mm",
  "flipper_length_mm", "body_mass_g")]
  my_knn_cv(data_train, data_cleaned$species, 1, 5)
  my_knn_cv(data_train, data_cleaned$species, 5, 5)

RolinaC/STAT302PACKAGE documentation built on Dec. 18, 2021, 10:59 a.m.