Edge of k-nearest neighbor classifier by resubstitution
Create a k-nearest neighbor classifier for the Fisher iris data, where = 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.
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.