my_knn_cv: K-Nearest-Neighbors Cross Validation

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

Performs k-nearest-neighbors cross validation on dataset to predict classifications of the data.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Data frame containing data to train the model.

cl

Data frame containing true classification values for the data.

k_nn

Numeric denoting how many nearest neighbors to use in the model.

k_cv

Numeric denoting number of folds to use in cross validation.

Value

List containing "class": vector of classification predictions made by the model, "cv_err": numeric containing the average misclasification rate from 0 to 1.

Examples

1
2
3
4
5
height <- c(1.87, 1.45, 1.67, 1.82, 1.91, 1.58)
weight <- c(210, 140, 165, 185, 205, 130)
gender <- c("Male", "Female", "Female", "Male", "Male", "Male")
df <- cbind(data.frame(height), data.frame(weight), data.frame(gender))
my_knn_cv(df[,1:2], df[,3], 1, 2)

BenjaminLowry/project3package documentation built on March 21, 2021, 4:34 a.m.