my_knn_cv: k-Nearest Neighbors Cross-Validation

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function implements knn to perform cross-validation.

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 with objects:

class

A vector of the predicted class for all observations.

cv_err

A numeric with the cross-validation misclassification error.

Examples

1
2
3
4
5
data <- na.omit(my_penguins)
data$species <- as.numeric(factor(data$species,
  levels = c('Adelie', 'Chinstrap', 'Gentoo'), labels = c(1, 2, 3)))
my_knn_cv(data[, 3:6], data[, 1], 1, 5)
my_knn_cv(data[, 3:6], data[, 1], 5, 5)

mzhang98/project3 documentation built on March 22, 2021, 1:51 p.m.