# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

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

# resubPredict

Class: ClassificationKNN

Predict resubstitution response of k-nearest neighbor classifier

## Syntax

```label = resubPredict(mdl)[label,score] = resubPredict(mdl)[label,score,cost] = resubPredict(mdl)```

## Description

`label = resubPredict(mdl)` returns the labels `mdl` predicts for the data `mdl.X`. `label` is the predictions of `mdl` on the data that `fitcknn` used to create `mdl`.

```[label,score] = resubPredict(mdl)``` returns the posterior class probabilities for the predictions.

```[label,score,cost] = resubPredict(mdl)``` returns the misclassification costs.

## Input Arguments

expand all

k-nearest neighbor classifier model, returned as a classifier model object.

Note that using the `'CrossVal'`, `'KFold'`, `'Holdout'`, `'Leaveout'`, or `'CVPartition'` options results in a model of class `ClassificationPartitionedModel`. You cannot use a partitioned tree for prediction, so this kind of tree does not have a `predict` method.

Otherwise, `mdl` is of class `ClassificationKNN`, and you can use the `predict` method to make predictions.

## Output Arguments

 `label` Predicted class labels for the points in the training data `X`, a vector with length equal to the number of rows in the training data `X`. The label is the class with minimal expected cost (see Expected Cost). `score` Numeric matrix of size `N`-by-`K`, where `N` is the number of observations (rows) in the training data `X`, and `K` is the number of classes (in `mdl.ClassNames`). `score(i,j)` is the posterior probability that row `i` of `X` is of class `j`. See Posterior Probability. `cost` Matrix of expected costs of size `N`-by-`K`, where `N` is the number of observations (rows) in the training data `X`, and `K` is the number of classes (in `mdl.ClassNames`). `cost(i,j)` is the cost of classifying row `i` of `X` as class `j`. See Expected Cost.

## Examples

expand all

Examine the quality of a classifier by its resubstitution predictions.

```load fisheriris X = meas; Y = species; ```

Construct a classifier for 5-nearest neighbors.

```mdl = fitcknn(X,Y,'NumNeighbors',5); ```

Generate the resubstitution predictions.

```label = resubPredict(mdl); ```

Calculate the number of differences between the predictions `label` and the original data `Y`.

```mydiff = not(strcmp(Y,label)); % mydiff(i) = 1 means they differ sum(mydiff) % Number of differences ```
```ans = 5 ```

A values of `1` in `mydiff` indicates that the observed label differs from the corresponding predicted label. There are `5` misclassifications.

expand all

## Algorithms

If you specified to standardize the predictor data, that is, `mdl.Mu` and `mdl.Sigma` are not empty (`[]`), then `resubPredict` standardizes the predictor data before predicting labels.