Description Usage Arguments Value Examples
This function calculates a k-fold cross validation for the k nearest neighbors algorithm.
1 | my_knn_cv(train, cl, k_nn, k_cv)
|
train |
Is a matrix with no NAs or missing values that is used to train the model. |
cl |
Is the true classification of the training data. |
k_nn |
Is the number of nearest neighbors to include in the cross validation calculation. |
k_cv |
Is the number of folds to use for the cross validation (common Ks are 2,5, and 10). |
Type list with a cv_err
object and the predicted classification class
output.
1 2 3 4 5 6 | set.seed(1)
rand_data <- data.frame(x1 = rnorm(100,0,1),x2 = rnorm(100,2,1))
rand_data_cl <- data.frame(y = rbinom(100,1,.3))
my_knn_cv(rand_data,rand_data_cl,k_nn = 5,k_cv = 5)
my_knn_cv(rand_data,rand_data_cl,k_nn = 5,k_cv = 10)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.