Description Usage Arguments Value Author(s) References See Also Examples

Carries out a k-nearest neighbor classification on the training data. Various additional output is produced for the purpose of constructing graphical displays such as the `classmap`

.

1 | ```
vcr.knn.train(X,y,k)
``` |

`X` |
This can be a rectangular matrix or data frame of (already standardized) measurements, or a dist object obtained from |

`y` |
factor with the given (observed) class labels. There need to be non-missing |

`k` |
the number of nearest neighbors used. It can be selected by running cross-validation using a different package. |

A list with components:

`yint` |
number of the given class of each case. Can contain |

`y` |
given class label of each case. Can contain |

`levels` |
levels of |

`predint` |
predicted class number of each case. Always exists. |

`pred` |
predicted label of each case. |

`altint` |
number of the alternative class. Among the classes different from the given class, it is the one with the highest posterior probability. Is |

`altlab` |
label of the alternative class. Is |

`PAC` |
probability of the alternative class. Is |

`figparams` |
parameters used to compute |

`fig` |
distance of each case |

`farness` |
farness of each case from its given class. Is |

`ofarness` |
for each case |

`k` |
the requested number of nearest neighbors, from the arguments. Will also be used for classifying new data. |

`ktrues` |
for each case this contains the actual number of elements in its neighborhood. This can be higher than |

`counts` |
a matrix with 3 columns, each row representing a case. For the neighborhood of each case it says how many members it has from the given class, the predicted class, and the alternative class. The first and third entry is |

`X` |
If the argument |

Raymaekers J., Rousseeuw P.J.

Raymaekers J., Rousseeuw P.J., Hubert M. (2021). Class maps for visualizing
classification results. *Technometrics*, forthcoming. (link to open access pdf)

1 2 3 4 5 6 7 8 | ```
vcrout = vcr.knn.train(iris[,1:4], iris[,5], k = 5)
confmat.vcr(vcrout)
stackedplot(vcrout)
classmap(vcrout, "versicolor", classCols = 2:4)
# The cases misclassified as virginica are shown in blue.
# For more examples, we refer to the vignette:
vignette("K_nearest_neighbors_examples")
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.