Description Usage Arguments Value Examples
This function uses k-nearest neighbor analysis to generate predicted classifications for an input dataset based on input covariates. Also uses cross-validation to compute average misclassification rate in order to assist in the selection of an optimal value of k.
1 | my_knn_cv(train, cl, k_nn, k_cv)
|
train |
A data frame of training set cases. Include only covariates of interest to be used in predicting class. |
cl |
A vector including the true class values of the training data |
k_nn |
An integer representing the number of neighbors considered. |
k_cv |
An integer representing the number of folds used in cross-validation. |
A list with the following elements:
"class"
: a vector of the predicted class for all observations,
and "cv_err"
: a numeric with the cross-validation misclassification
error.
1 2 | penguins <- tidyr::drop_na(my_penguins)
my_knn_cv(penguins[, 3:6], penguins$species, 1, 5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.