my_knn_cv: k-Nearest Neighbors Cross-Validation

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function randomly splits data into k "folds" and predicts class using covariates.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

A data frame of the covariates (elements are numeric).

cl

True class value of the training data.

k_nn

Integer of the number of neighbors.

k_cv

Integer of the number of folds.

Value

A list containing:

class, a vector of the predicted class.

CV_error, a numeric of the average cross-validation misclassification error rate.

Examples

1
2
3
4
data(iris)

# 5-nearest neighbor CV with iris data
my_knn_cv(iris[, 1:4], iris$Species, k_nn = 5, k_cv = 5)

hchang23/firstpackage documentation built on March 18, 2020, 7:37 a.m.