www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CreateCrossValidatedMulticlassLinearClassificationModelExample.m
%% Create Cross-Validated Multiclass Linear Classification Model %% % 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 a multiclass, linear classification model that can % identify which MATLAB(R) toolbox a documentation web page is from % based on counts of words on the page. rng(1); % For reproducibility CVMdl = fitcecoc(X,Y,'Learners','linear','CrossVal','on') %% % |CVMdl| is a |ClassificationPartitionedLinearECOC| cross-validated model. % Because |fitcecoc| implements 10-fold cross-validation by default, % |CVMdl.Trained| contains a 10-by-1 cell vector of ten % |CompactClassificationECOC| models that contain the results of training % ECOC models composed of binary, linear classification models for each of % the folds. %% % Estimate labels for out-of-fold observations and estimate the % generalization error by passing |CVMdl| to |kfoldPredict| and % |kfoldLoss|, respectively. oofLabels = kfoldPredict(CVMdl); ge = kfoldLoss(CVMdl) %% % The estimated generalization error is about 10% misclassified % observations. %% % To improve generalization error, try specifying another solver, such as % LBFGS. To change default options when training ECOC models composed of % linear classification models, create a linear classification model % template using |templateLinear|, and then pass the template to % |fitcecoc|.