www.gusucode.com > stats 源码程序 matlab案例代码 > stats/DisplayIndividualLossesForEachCrossValidationFoldExample.m
%% Display Individual Losses for Each Cross-Validation Fold % The classification loss is a measure of classifier quality. You % can determine ill-performing folds by displaying the losses for each fold. %% % Load Fisher's iris data set. % Copyright 2015 The MathWorks, Inc. load fisheriris X = meas; Y = categorical(species); classOrder = unique(Y); rng(1); % For reproducibility %% % Train an ECOC model using SVM binary classifiers and specify to use % 8-fold cross validation. It is good practice to standardize the % predictors and define the class order. Specify to standardize the % predictors using an SVM template. t = templateSVM('Standardize',1); CVMdl = fitcecoc(X,Y,'KFold',8,'Learners',t,'ClassNames',classOrder); %% % Estimate the average classification loss across folds, and the losses for % each fold. loss = kfoldLoss(CVMdl) losses = kfoldLoss(CVMdl,'Mode','individual') %% % The third fold misclassifies a much higher portion of observations than % any other fold. %% % Return the classification loss for the entire model by specifying % the well-performing folds using the |'Folds'| name-value pair argument. loss = kfoldLoss(CVMdl,'Folds',[1:2 4:8]) %% % The total classification loss decreased by approximately half its % original size. %% % Consider adjusting parameters of the binary classifiers or the coding % design to see if performance for all folds improves.