my_knn_cv: K-nearest Neighbors

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function uses k nearest neighbors to train a knn model and test it using k-fold cross validation.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

a matrix representing the prediction variables for the result

cl

a numeric vector indicating the true result

k_nn

the number of nearest neighbors to use when training the model

k_cv

the number of folds to use when performing cross-validation

Value

a list with the predicted values of cl and the mean squared error of the cross-validation testing

Examples

1
2
3
subset <- my_gapminder[c("year", "lifeExp", "pop")]
resp <- my_gapminder %>% dplyr::pull(gdpPercap)
my_knn_cv(subset, resp, 2, 5)

Codax2000/mypackage documentation built on Dec. 17, 2021, 2:59 p.m.