vcr.knn.train {classmap} | R Documentation |
Carry out a k-nearest neighbor classification on training data, and prepare to visualize its results.
Description
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
.
Usage
vcr.knn.train(X, y, k)
Arguments
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. |
Value
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 |
Author(s)
Raymaekers J., Rousseeuw P.J.
References
Raymaekers J., Rousseeuw P.J., Hubert M. (2021). Class maps for visualizing classification results. Technometrics, appeared online. doi: 10.1080/00401706.2021.1927849(link to open access pdf)
See Also
vcr.knn.newdata
, classmap
, silplot
, stackedplot
Examples
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:
## Not run:
vignette("K_nearest_neighbors_examples")
## End(Not run)