my_knn_cv: My_knn_cv

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function calculates a k-fold cross validation for the k nearest neighbors algorithm.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Is a matrix with no NAs or missing values that is used to train the model.

cl

Is the true classification of the training data.

k_nn

Is the number of nearest neighbors to include in the cross validation calculation.

k_cv

Is the number of folds to use for the cross validation (common Ks are 2,5, and 10).

Value

Type list with a cv_err object and the predicted classification class output.

Examples

1
2
3
4
5
6
set.seed(1)

rand_data <- data.frame(x1 = rnorm(100,0,1),x2 = rnorm(100,2,1))
rand_data_cl <- data.frame(y = rbinom(100,1,.3))
my_knn_cv(rand_data,rand_data_cl,k_nn = 5,k_cv = 5)
my_knn_cv(rand_data,rand_data_cl,k_nn = 5,k_cv = 10)

theloniousgoerz/tgpackage documentation built on Dec. 23, 2021, 9:54 a.m.