www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimatekFoldCrossValidationClassificationError1Example.m

    %% Estimate _k_-Fold Cross-Validation Classification Error
%%
% Load the NLP data set.
load nlpdata
%%
% |X| is a sparse matrix of predictor data, and |Y| is a categorical vector
% of class labels.
%%
% Cross-validate an ECOC model of linear classification models. 
rng(1); % For reproducibility 
CVMdl = fitcecoc(X,Y,'Learner','linear','CrossVal','on');
%%
% |CVMdl| is a |ClassificationPartitionedLinearECOC| model. By default, the
% software implements 10-fold cross validation.
%%
% Estimate the average of the out-of-fold classification error rates.
ce = kfoldLoss(CVMdl)
%%
% Alternatively, you can obtain the per-fold classification error rates by
% specifying the name-value pair |'Mode','individual'| in |kfoldLoss|.