CVerrorknn {smallstuff}R Documentation

k-Fold Cross Validation Error Rate for KNN

Description

Given a dataset with predictors and a vector with responses, a number of neighbors K, and a number of folds k, the k-fold CV error rate for KNN is calculated.

Usage

CVerrorknn(pred, resp, K = 1, k = nrow(pred))

Arguments

pred

A dataset with predictors

resp

A vector with responses

K

The number of neighborhoods to consider when performing KNN

k

The number of folds

Value

The k-fold CV error rate if k is entered, otherwise the LOOCV error rate.

Examples

mtcars$am=as.factor(mtcars$am)
CVerrorknn(mtcars[,c("mpg","hp")],mtcars$am)

[Package smallstuff version 1.0.3 Index]