www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TrainMulticlassLinearClassificationModelExample.m
%% Train Multiclass Linear Classification Model % Train an ECOC model composed of multiple binary, linear classification % models. %% % Load the NLP data set. load nlpdata %% % |X| is a sparse matrix of predictor data, and |Y| is a categorical vector % of class labels. There are more than two classes in the data. %% % Create a default linear-classification-model template. t = templateLinear(); %% % To adjust the default values, see <docid:stats_ug.bu216oi % templateLinear>. %% % Train an ECOC model composed of multiple binary, linear classification % models that can identify the product given the frequency distribution of % words on a documentation web page. For faster training time, transpose % the predictor data, and specify that observations correspond to columns. X = X'; rng(1); % For reproducibility Mdl = fitcecoc(X,Y,'Learners',t,'ObservationsIn','columns') %% % Alternatively, you can train an ECOC model composed of default linear % classification models using |'Learners','Linear'|. %% % To conserve memory, |fitcecoc| returns trained ECOC models composed of % linear classification learners in |CompactClassificationECOC| model % objects.