my_knn_cv: K-Nearest Neighbors function

Description Usage Arguments Value Examples

View source: R/my_knn_cv.R

Description

This function performs predicts an output class using covariates given in training data.

Usage

1
my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

An input data frame.

cl

The true class value of the training data.

k_nn

An integer representing the number of neighbors to use.

k_cv

An integer representing the number of folds to use.

Value

A list with objects class (a vector of the predicted class for all observations) and cv_err (a numeric with the cross-validation misclassification error).

Examples

1
2
3
4
train_dat <- subset(na.omit(my_penguins), select = c(bill_length_mm,
  bill_depth_mm, flipper_length_mm, body_mass_g))
correct <- data.frame("species" = na.omit(my_penguins)$species)
my_knn_cv(train_dat, correct, 1, 5)

CamSims/myfirstpackage documentation built on Dec. 17, 2021, 1:56 p.m.