predict.classifier | R Documentation |
Predicts class labels and probabilities for new data using a fitted classifier
object.
It performs k-Nearest Neighbors (k-NN) classification in the projected component space.
## S3 method for class 'classifier'
predict(
object,
new_data,
ncomp = NULL,
colind = NULL,
metric = c("euclidean", "cosine", "ejaccard"),
normalize_probs = FALSE,
prob_type = c("knn_proportion", "avg_similarity"),
...
)
object |
A fitted object of class |
new_data |
A numeric matrix or vector of new observations to classify. Rows are observations,
columns are variables matching the original data space used by the projector OR matching |
ncomp |
Optional integer; the number of components to use from the projector for classification (default: all components used during classifier creation). |
colind |
Optional numeric vector specifying column indices from the original data space.
If provided, |
metric |
Character string specifying the similarity or distance metric for k-NN. Choices: "euclidean", "cosine", "ejaccard". |
normalize_probs |
Logical; DEPRECATED Normalization behavior is now implicit in |
prob_type |
Character string; method for calculating probabilities:
|
... |
Extra arguments passed down to projection methods ( |
The function first projects the new_data
into the component space defined by the
classifier's internal projector. If colind
is specified, a partial projection using
only those features is performed. This projection is then compared to the reference scores
stored within the classifier
object (object$scores
) using the specified metric
.
The k-NN algorithm identifies the k
nearest reference samples (based on similarity or distance)
and predicts the class via majority vote. Probabilities are estimated based on the average
similarity/distance to each class among the neighbors or all reference points.
A list containing:
class |
A factor vector of predicted class labels for |
prob |
A numeric matrix (rows corresponding to |
classifier.projector
, classifier.multiblock_biprojector
, partial_project
Other classifier predict:
predict.rf_classifier()
# Assume clf is a fitted classifier object (e.g., from classifier.projector)
# Assume new_dat is a matrix of new observations
# preds <- predict(clf, new_data = new_dat, metric = "cosine")
# print(preds$class)
# print(preds$prob)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.