www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CreateKNearestNeighborsTemplateForECOCMulticlassLearningExample.m
%% Create a _k_-Nearest Neighbors Template for ECOC Multiclass Learning % Create a nondefault _k_-nearest neighbor template for use in % |fitcecoc|. %% % Load Fisher's iris data set. % Copyright 2015 The MathWorks, Inc. load fisheriris %% % Create a template for a 5-nearest neighbor search, and specify to % standardize the predictors. t = templateKNN('NumNeighbors',5,'Standardize',1) %% % All properties of the template object are empty except for % |NumNeighbors|, |Method|, |StandardizeData|, and |Type|. When you specify % |t| as a learner, the software fills in the empty properties with their % respective default values. %% % Specify |t| as a binary learner for an ECOC multiclass model. Mdl = fitcecoc(meas,species,'Learners',t); %% % By default, the software trains |Mdl| using the one-versus-one coding % design. %% % Display the in-sample (resubstitution) misclassification error. L = resubLoss(Mdl,'LossFun','classiferror')