www.gusucode.com > stats 源码程序 matlab案例代码 > stats/EstimatekFoldCrossValidationEdgeExample.m
%% Estimate _k_-Fold Cross-Validation Edge %% % Load the NLP data set. load nlpdata %% % |X| is a sparse matrix of predictor data, and |Y| is a categorical vector % of class labels. %% % For simplicity, use the label 'others' for all observations in |Y| that % are not |'simulink'|, |'dsp'|, or |'comm'|. Y(~(ismember(Y,{'simulink','dsp','comm'}))) = 'others'; %% % Cross-validate a multiclass, linear classification model. 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. You can alter the number % of folds using the |'KFold'| name-value pair argument. %% % Estimate the average of the out-of-fold edges. e = kfoldEdge(CVMdl) %% % Alternatively, you can obtain the per-fold edges by specifying the % name-value pair |'Mode','individual'| in |kfoldEdge|.