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 a k-neareast neighbors cross-validation. predicts "species" using four covariates bill_length_mm, bill_depth_mm, flipper_length_mm, and body_mass_g.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Input data frame.

cl

True class value of the training data.

k_nn

Integer representing the number of neighbors.

k_cv

Integer representing the number of folds.

Value

A list of the predicted class and the CV misclassification rate.

Examples

1
2
3
4
penguins_01 <- na.omit(my_penguins)
species_outcome <- dplyr::pull(penguins_01, var = "species")
penguins_01 <- dplyr::select(penguins_01, 3:6)
my_knn_cv(penguins_01, species_outcome, 5, 10)

YuxinHuang0723/samplepackage documentation built on Dec. 18, 2021, 8:24 p.m.