Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

**Class: **ClassificationKNN

Predict labels using *k*-nearest neighbor
classification model

`label = predict(Mdl,X)`

```
[label,score,cost]
= predict(Mdl,X)
```

returns
a vector of predicted
class label for the predictor data in the table or matrix `label`

= predict(`Mdl`

,`X`

)`X`

,
based on the trained *k*-nearest neighbor classification
model `Mdl`

.

`[`

also
returns:`label`

,`score`

,`cost`

]
= predict(`Mdl`

,`X`

)

A matrix of classification scores (

`score`

) indicating the likelihood that a label comes from a particular class. For*k*-nearest neighbor, scores are posterior probabilities.A matrix of expected classification cost (

`cost`

). For each observation in`X`

, the predicted class label corresponds to the minimum expected classification costs among all classes.

Was this topic helpful?