www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CrossValidatingADiscriminantAnalysisClassifierExample.m
%% Cross Validating a Discriminant Analysis Classifier % This example shows how to perform five-fold cross validation of a % quadratic discriminant analysis classifier. %% % Load the sample data. % Copyright 2015 The MathWorks, Inc. load fisheriris %% % Create a quadratic discriminant analysis classifier for the data. quadisc = fitcdiscr(meas,species,'DiscrimType','quadratic'); %% % Find the resubstitution error of the classifier. qerror = resubLoss(quadisc) %% % The classifier does an excellent job. Nevertheless, resubstitution error % can be an optimistic estimate of the error when classifying new data. So % proceed to cross validation. %% % Create a cross-validation model. cvmodel = crossval(quadisc,'kfold',5); %% % Find the cross-validation loss for the model, meaning the error of the % out-of-fold observations. cverror = kfoldLoss(cvmodel) %% % The cross-validated loss is as low as the original resubstitution % loss. Therefore, you can have confidence that the classifier is % reasonably accurate.