vcr.knn.train: Prepare classmap for k-nearest neighbors

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

View source: R/VCR_knn.R

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

1

Arguments

X

This can be a rectangular matrix or data frame of (already standardized) measurements, or a dist object obtained from stats::dist or cluster::daisy. Missing values are not allowed.

y

factor with the given (observed) class labels. There need to be non-missing y in order to be able to train the classifier.

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 NA's.

y

given class label of each case. Can contain NA's.

levels

levels of y

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 NA for cases whose y is missing.

altlab

label of the alternative class. Is NA for cases whose y is missing.

PAC

probability of the alternative class. Is NA for cases whose y is missing.

figparams

parameters used to compute fig.

fig

distance of each case i from each class g. Always exists.

farness

farness of each case from its given class. Is NA for cases whose y is missing.

ofarness

for each case i, its lowest fig[i,g] to any class g. Always exists.

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 k due to ties.

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 NA for cases whose y is missing.

X

If the argument X was a data frame or matrix of coordinates, as.matrix(X) is returned here. This is useful for classifying new data.

Author(s)

Raymaekers J., Rousseeuw P.J.

References

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

See Also

vcr.knn.newdata, classmap

Examples

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")

classmap documentation built on May 10, 2021, 9:10 a.m.