Learn R Programming

smallstuff (version 1.0.3)

CVerrorknn: 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))

Value

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

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

Examples

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

Run the code above in your browser using DataLab