Class: ClassificationKNN

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 (see Edge).

Input Arguments

collapse all

mdl — Classifier modelclassifier model object

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


Classification edge, a scalar that is the mean classification margin (see Margin).



The edge is the mean value of the classification margin.


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

Margin is 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 that have that classification, divided by the number of neighbors. For a more detailed definition that includes weights and prior probabilities, see Posterior Probability.


collapse all

Resubstitution Edge Calculation

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

Load the data.

load fisheriris
X = meas;
Y = species;

Construct a classifier for 5-nearest neighbors.

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

Examine the resubstitution edge of the classifier.

E = resubEdge(mdl)
E =


Related Examples

Was this topic helpful?