www.gusucode.com > stats 源码程序 matlab案例代码 > stats/KNNTemplateforNondefaultOptionsExample.m
%% Create a _k_-Nearest Neighbors Template for Ensemble % Create a nondefault _k_-nearest neighbor template for use in % |fitensemble|. % Copyright 2015 The MathWorks, Inc. %% % Load Fisher's iris data set. 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 weak learner for a classification ensemble. Mdl = fitensemble(meas,species,'Subspace',100,t); %% % Display the in-sample (resubstitution) misclassification error. L = resubLoss(Mdl)