# resubEdge

Edge of k-nearest neighbor classifier by resubstitution

## Syntax

``E = resubEdge(mdl)``

## Description

example

````E = resubEdge(mdl)` returns the classification edge for `mdl` with the data used to train `mdl`.The classification edge (`E`) is a scalar value that represents the mean of the classification margins.```

## Examples

collapse all

Create a k-nearest neighbor classifier for the Fisher iris data, where $k$ = 5.

Load the Fisher iris data set.

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

Create a classifier for five nearest neighbors.

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

Examine the resubstitution edge of the classifier.

`E = resubEdge(mdl)`
```E = 0.9253 ```

`E` is the mean of the training sample margins.

## Input Arguments

collapse all

k-nearest neighbor classifier model, specified as a `ClassificationKNN` object.

collapse all

### Margin

The classification margin for each observation is the difference between the classification score for the true class and the maximal classification score for the false classes.

The classification margins form a column vector with the same number of rows as in the training data.

### Score

The score of a classification is the posterior probability of the classification. The posterior probability is the number of neighbors with that classification divided by the number of neighbors. For a more detailed definition that includes weights and prior probabilities, see Posterior Probability.