This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Edge of k-nearest neighbor classifier by resubstitution


E = resubEdge(mdl)



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.


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.

More About

collapse all


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.


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.

Introduced in R2012a