my_knn_cv: K-Nearest Neighbors Cross-Validatin

View source: R/my_knn_cv.R

my_knn_cvR Documentation

K-Nearest Neighbors Cross-Validatin

Description

It uses the k-nearest-neighbors method to predict the output. For example, it can predict the class Species in iris data using covariates Sepal.Length, Sepal.Width, Petal.Length, and Petal.Width.

Usage

my_knn_cv(train, cl, k_nn, k_cv)

Arguments

train

Input data frame.

cl

A data frame that contains the true class value of the input training data train.

k_nn

Integer representing the number of neighbors.

k_cv

Integer representing the number of folds.

Value

A list containing the following objects:

  • class: objects class that contains a vector of the predicted class for all observations.

  • cv_error: a numeric represents cross-validation misclassification error.

Examples

# an example that uses iris data
my_knn_cv(iris[, -5], iris[, 5], 5, 5)


yinuotxie/package302 documentation built on April 29, 2023, 7:13 a.m.