discardSupportVectors

Discard support vectors of linear SVM binary learners in ECOC model

Description

example

Mdl = discardSupportVectors(MdlSV) returns a trained multiclass error-correcting output codes (ECOC) model (Mdl) from the trained multiclass ECOC model (MdlSV), which contains at least one linear CompactClassificationSVM binary learner. Both Mdl and MdlSV are objects of the same type, either ClassificationECOC objects or CompactClassificationECOC objects.

Mdl has these characteristics:

Examples

collapse all

When you train an ECOC model with linear SVM binary learners, fitcecoc empties the Alpha, SupportVectorLabels, and SupportVectors properties of the binary learners by default. You can choose instead to retain the support vectors and related values, and then discard them from the model later.

Load Fisher's iris data set.

load fisheriris
rng(1); % For reproducibility

Train an ECOC model using the entire data set. Specify retaining the support vectors by passing in the appropriate SVM template.

t = templateSVM('SaveSupportVectors',true);
MdlSV = fitcecoc(meas,species,'Learners',t);

MdlSV is a trained ClassificationECOC model with linear SVM binary learners. By default, fitcecoc implements a one-versus-one coding design, which requires three binary learners for three-class learning.

Access the estimated α (alpha) values using dot notation.

alpha = cell(3,1);
alpha{1} = MdlSV.BinaryLearners{1}.Alpha;
alpha{2} = MdlSV.BinaryLearners{2}.Alpha;
alpha{3} = MdlSV.BinaryLearners{3}.Alpha;
alpha
alpha=3×1 cell
    { 3x1 double}
    { 3x1 double}
    {23x1 double}

alpha is a 3-by-1 cell array that stores the estimated values of α.

Discard the support vectors and related values from the ECOC model.

Mdl = discardSupportVectors(MdlSV);

Mdl is similar to MdlSV, except that the Alpha, SupportVectorLabels, and SupportVectors properties of all the linear SVM binary learners are empty ([]).

areAllEmpty = @(x)isempty([x.Alpha x.SupportVectors x.SupportVectorLabels]);
cellfun(areAllEmpty,Mdl.BinaryLearners)
ans = 3x1 logical array

   1
   1
   1

Compare the sizes of the two ECOC models.

vars = whos('Mdl','MdlSV');
100*(1 - vars(1).bytes/vars(2).bytes)
ans = 4.6743

Mdl is about 5% smaller than MdlSV.

Reduce your memory usage by compacting Mdl and then clearing Mdl and MdlSV from the workspace.

CompactMdl = compact(Mdl);
clear Mdl MdlSV;

Predict the label for a random row of the training data using the more efficient SVM model.

idx = randsample(size(meas,1),1)
idx = 63
predictedLabel = predict(CompactMdl,meas(idx,:))
predictedLabel = 1x1 cell array
    {'versicolor'}

trueLabel = species(idx)
trueLabel = 1x1 cell array
    {'versicolor'}

Input Arguments

collapse all

Full or compact, trained multiclass ECOC model containing at least one linear SVM binary learner, specified as a ClassificationECOC or CompactClassificationECOC model.

More About

collapse all

Linear SVM Binary Learner

In the context of this page, a linear support vector machine (SVM) binary learner is a binary SVM classifier created using a linear kernel function. If the jth binary learner in an ECOC model Mdl is a linear SVM binary learner, then Mdl.BinaryLearners{j} is a CompactClassificationSVM object, where Mdl.BinaryLearners{j}.KernelParameters.Function is 'linear'.

Tips

  • By default and for efficiency, fitcecoc empties the Alpha, SupportVectorLabels, and SupportVectors properties for all linear SVM binary learners. fitcecoc lists Beta, rather than Alpha, in the model display.

    To store Alpha, SupportVectorLabels, and SupportVectors, pass a linear SVM template that specifies storing support vectors to fitcecoc. For example, enter:

    t = templateSVM('SaveSupportVectors',true)
    Mdl = fitcecoc(X,Y,'Learners',t);

    You can remove the support vectors and related values by passing the resulting ClassificationECOC model to discardSupportVectors.

Algorithms

predict and resubPredict estimate SVM scores f(x) for each linear SVM binary learner in an ECOC model using

f(x)=xβ+b.

β is the Beta property and b is the Bias property of the binary learners. You can access these properties for each linear SVM binary learner in the cell array Mdl.BinaryLearners. For more details on the SVM score calculation, see Support Vector Machines for Binary Classification.

Introduced in R2015a