| vcr.knn.newdata | R Documentation |
Predicts class labels for new data by k nearest neighbors, using the output of vcr.knn.train on the training data. For cases in the new data whose given label ynew is not NA, additional output is produced for constructing graphical displays such as the classmap.
vcr.knn.newdata(Xnew, ynew = NULL, vcr.knn.train.out, LOO = FALSE)
Xnew |
If the training data was a matrix of coordinates, |
ynew |
factor with class membership of each new case. Can be |
vcr.knn.train.out |
output of |
LOO |
leave one out. Only used when testing this function on a subset of the training data. Default is |
A list with components:
yintnew |
number of the given class of each case. Can contain |
ynew |
given class label of each case. Can contain |
levels |
levels of the response, from |
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 |
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 |
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 |
Raymaekers J., Rousseeuw P.J.
Raymaekers J., Rousseeuw P.J., Hubert M. (2021). Class maps for visualizing classification results. Technometrics, 64(2), 151–165. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/00401706.2021.1927849")}
vcr.knn.train, classmap, silplot, stackedplot
data("data_floralbuds")
X <- data_floralbuds[, 1:6]; y <- data_floralbuds[, 7]
set.seed(12345); trainset <- sample(1:550, 275)
vcr.train <- vcr.knn.train(X[trainset, ], y[trainset], k = 5)
vcr.test <- vcr.knn.newdata(X[-trainset, ], y[-trainset], vcr.train)
confmat.vcr(vcr.train) # for comparison
confmat.vcr(vcr.test)
cols <- c("saddlebrown", "orange", "olivedrab4", "royalblue3")
stackedplot(vcr.train, classCols = cols) # for comparison
stackedplot(vcr.test, classCols = cols)
classmap(vcr.train, "bud", classCols = cols) # for comparison
classmap(vcr.test, "bud", classCols = cols)
# For more examples, we refer to the vignette:
## Not run:
vignette("K_nearest_neighbors_examples")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.