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

    %% Reduce the Size of Full ECOC Models
% Full ECOC models (i.e., |ClassificationECOC| models) hold the
% training data.  For efficiency, you might not want to predict new labels
% using a large classifier.
%%
% Load Fisher's iris data set.

% Copyright 2015 The MathWorks, Inc.

load fisheriris
X = meas;
Y = categorical(species);
classOrder = unique(Y);
%%
% Train an ECOC model using SVM binary classifiers. 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);
Mdl = fitcecoc(X,Y,'Learners',t,'ClassNames',classOrder);
%%
% |t| is an SVM template object. The software uses default values for empty
% options in |t| during training. |Mdl| is a |ClassificationECOC| model.
%%
% Reduce the size of the trained ECOC model.
CMdl = compact(Mdl)
%%
% |CMdl| is a |CompactClassificationECOC| model.  It does not store the
% training data nor some of the properties that |Mdl| stores.
%%
% Display how much memory each classifier uses.
whos('Mdl','CMdl')
%%
% The full ECOC model (|Mdl|) is approximately double the size of the
% compact ECOC model (|CMdl|).
%%
% You can remove |Mdl| from the MATLAB(R) Workspace, and pass
% |CMdl| and new predictor values to |predict| to efficiently
% label new observations.