Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

CompactClassificationECOC

Paquete: classreg.learning.classif

Compact multiclass model for support vector machines or other classifiers

Description

CompactClassificationECOC is a compact, multiclass, error-correcting output codes (ECOC) model.

The compact classifier does not include the data used for training the ECOC multiclass model. Therefore, you cannot perform tasks, such as cross-validation, using the compact classifier.

Use a compact ECOC multiclass model for labeling new data (in other words, predicting the labels of new data).

Construction

CompactMdl = compact(Mdl) returns a compact, multiclass ECOC model (CompactModel) from a full, trained, multiclass, ECOC model (Mdl).

CompactMdl = fitcecoc(X,Y,'Learners',t) returns a compact ECOC model composed of either linear classification models (ClassificationLinear model objects) or kernel classification models (ClassificationKernel model objects). t must be 'linear' or 'kernel', a linear classification model template object returned by templateLinear, or a kernel classification model template object returned by templateKernel. For more details, see fitcecoc.

Input Arguments

expandir todo

Full, trained, multiclass, ECOC model, specified as a ClassificationECOC classifier trained by fitcecoc.

Predictor data, specified as an n-by-p full or sparse matrix.

The length of Y and the number of observations in X must be equal.

Tipos de datos: single | double

Class labels to which the classification linear model is trained, specified as a categorical, character, or string array, logical or numeric vector, or cell array of character vectors.

If Y is a character array, each element must correspond to one row of the array. The length of Y and the number of observations in X must be equal.

Tipos de datos: categorical | char | string | logical | single | double | cell

Propiedades

expandir todo

Trained binary learners, specified as a cell vector of model objects. BinaryLearners has as many elements as classes in Y.

The software trained BinaryLearner{j} according to the binary problem specified by CodingMatrix(:,j). For example, for multiclass learning using SVM learners, each element of BinaryLearners is a CompactClassificationSVM classifier.

Tipos de datos: cell

Binary learner loss function, specified as a character vector representing the loss function name.

If you train using binary learners that use different loss functions, then the software sets BinaryLoss to 'hamming'. To potentially increase accuracy, set a different binary loss function than this default during prediction or loss computation using the BinaryLoss name-value pair argument of predict or loss.

Tipos de datos: char

Categorical predictor indices, specified as a vector of positive integers. CategoricalPredictors contains index values corresponding to the columns of the predictor data that contain categorical predictors. If none of the predictors are categorical, then this property is empty ([]).

Tipos de datos: single | double

Unique class labels used in training, specified as a categorical or character array, logical or numeric vector, or cell array of character vectors. ClassNames has the same data type as the class labels Y. (The software treats string arrays as cell arrays of character vectors.) ClassNames also determines the class order.

Tipos de datos: categorical | char | logical | single | double | cell

Class-assignment codes for the binary learners, specified as a numeric matrix. CodingMatrix is a K-by-L matrix, where K is the number of classes and L is the number of binary learners.

Elements of CodingMatrix are -1, 0, or 1, and the value corresponds to a dichotomous class assignment. This table describes the meaning of CodingMatrix(i,j), that is, the class that learner j assigns to observations in class i.

ValueDichotomous Class Assignment
–1Learner j assigns observations in class i to a negative class.
0Before training, learner j removes observations in class i from the data set.
1Learner j assigns observations in class i to a positive class.

Tipos de datos: double | single | int8 | int16 | int32 | int64

Esta propiedad es de solo lectura.

Misclassification costs, specified as a square numeric matrix. Cost has K rows and columns, where K is the number of classes.

Cost(i,j) is the cost of classifying a point into class j if its true class is i. The order of the rows and columns of Cost corresponds to the order of the classes in ClassNames.

fitcecoc incorporates misclassification costs differently among different types of binary learners.

Tipos de datos: double

Expanded predictor names, stored as a cell array of character vectors.

If the model uses encoding for categorical variables, then ExpandedPredictorNames includes the names that describe the expanded variables. Otherwise, ExpandedPredictorNames is the same as PredictorNames.

Binary learner weights, specified as a numeric row vector. LeanerWeights has length equal to the number of binary learners (size(CodingMatrix,2)).

LearnerWeights(j) is the sum of the observation weights that binary learner j used to train its classifier.

The software uses LearnerWeights to fit posterior probabilities by minimizing the Kullback-Leibler divergence.

Tipos de datos: double | single

Predictor names in order of their appearance in the predictor data X, specified as a cell array of character vectors. The length of PredictorNames is equal to the number of columns in X.

Tipos de datos: cell

Esta propiedad es de solo lectura.

Prior class probabilities, specified as a numeric vector. Prior has as many elements as there are classes in ClassNames, and the order of the elements corresponds to the elements of ClassNames.

fitcecoc incorporates misclassification costs differently among different types of binary learners.

Tipos de datos: double

Response variable name, specified as a character vector.

Tipos de datos: char

Score transformation function to apply to predicted scores, specified as a function name or function handle.

To change the score transformation function to function, for example, use dot notation.

  • For a built-in function, enter this code and replace function with a value in the table.

    Mdl.ScoreTransform = 'function';

    ValueDescription
    'doublelogit'1/(1 + e–2x)
    'invlogit'log(x / (1–x))
    'ismax'Sets the score for the class with the largest score to 1, and sets the scores for all other classes to 0
    'logit'1/(1 + ex)
    'none' or 'identity'x (no transformation)
    'sign'–1 for x < 0
    0 for x = 0
    1 for x > 0
    'symmetric'2x – 1
    'symmetricismax'Sets the score for the class with the largest score to 1, and sets the scores for all other classes to –1
    'symmetriclogit'2/(1 + ex) – 1

  • For a MATLAB® function or a function that you define, enter its function handle.

    Mdl.ScoreTransform = @function;

    function must accept a matrix (the original scores) and return a matrix of the same size (the transformed scores).

Tipos de datos: char | function_handle

Methods

discardSupportVectorsDiscard support vectors of linear support vector machine binary learners
edgeClassification edge for multiclass, error-correcting output codes model
lossClassification loss for multiclass, error-correcting output codes model
marginClassification margins for multiclass, error-correcting output codes model
predictPredict labels using multiclass, error-correcting output codes model
selectModelsChoose subset of regularized linear classification models

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).

Ejemplos

contraer todo

Full ECOC models (i.e., ClassificationECOC classifiers) hold the training data. For efficiency, you might not want to predict new labels using a large classifier.

Load Fisher's iris data set.

load fisheriris
X = meas;
Y = species;

Train an ECOC model using default SVMs as binary learners.

Mdl = fitcecoc(X,Y)
Mdl = 
  ClassificationECOC
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'setosa'  'versicolor'  'virginica'}
           ScoreTransform: 'none'
           BinaryLearners: {3x1 cell}
               CodingName: 'onevsone'


  Properties, Methods

Mdl is a ClassificationECOC model.

Reduce the size of the ECOC model.

CMdl = compact(Mdl)
CMdl = 
  classreg.learning.classif.CompactClassificationECOC
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'setosa'  'versicolor'  'virginica'}
           ScoreTransform: 'none'
           BinaryLearners: {3x1 cell}
             CodingMatrix: [3x3 double]


  Properties, Methods

CMdl is a CompactClassificationECOC model.

Display how much memory each classifier consumes.

whos('Mdl','CMdl')
  Name      Size            Bytes  Class                                                  Attributes

  CMdl      1x1             12764  classreg.learning.classif.CompactClassificationECOC              
  Mdl       1x1             25337  ClassificationECOC                                               

The full ECOC model (Mdl) is almost twice the size of the compact ECOC model (CMdl).

You can remove Mdl from the MATLAB® Workspace, and pass CMdl and new predictor values to predict to efficiently label new observations.

Train an ECOC classifier using different binary learners and the one-versus-all coding design. Then, cross validate the classifier.

Load Fisher's iris data set.

load fisheriris
X = meas;
Y = species;
classNames = unique(species(~strcmp(species,''))) % Remove empty classes 
classNames = 3x1 cell array
    {'setosa'    }
    {'versicolor'}
    {'virginica' }

K = numel(classNames) % Number of classes
K = 3
rng(1);  % For reproducibility

classNames are the unique classes in the data set, and K is the number of classes. You can use classNames to specify the order of the classes during training.

For a one-versus-all coding design, there are K = 3 binary learners. Specify templates for the binary learners such that:

  • Binary learner 1 and 2 are naive Bayes classifiers. By default, each predictor is conditionally, normally distributed given its label.

  • Binary learner 3 is an SVM classifier. Specify to use the Gaussian kernel.

tNB = templateNaiveBayes();
tSVM = templateSVM('KernelFunction','gaussian');
tLearners = {tNB tNB tSVM};

tNB and tSVM are template objects for naive Bayes and SVM learning, respectively. They indicate what options to use during training. Most of their properties are empty, except for those specified using name-value pair arguments. The software fills in the empty properties with their default values during training.

Train and cross-validate an ECOC classifier using the binary learner templates and the one-versus-all coding design. Specify the order of the classes. By default, naive Bayes classifiers use posterior probabilities as scores, whereas SVM classifiers use distance from the decision boundary. Therefore, to aggregate the binary learners, you must specify fitting posterior probabilities.

CVMdl = fitcecoc(X,Y,'ClassNames',classNames,'CrossVal','on',...
    'Learners',tLearners,'FitPosterior',1);

CVMdl is not a ClassificationECOC model, but a ClassificationPartitionedECOC cross-validated model. By default, the software implements 10-fold cross-validation. The scores across the binary learners are in the same form (that is, they are posterior probabilities), so the software can aggregate the results of the binary classifications properly.

Inspect one of the trained folds using dot notation.

CVMdl.Trained{1}
ans = 
  classreg.learning.classif.CompactClassificationECOC
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'setosa'  'versicolor'  'virginica'}
           ScoreTransform: 'none'
           BinaryLearners: {3x1 cell}
             CodingMatrix: [3x3 double]


  Properties, Methods

Each fold is a CompactClassificationECOC model trained on 90% of the data.

You can access the results of the binary learners using dot notation and cell indexing. Display the trained SVM classifier (the third binary learner) in the first fold.

CVMdl.Trained{1}.BinaryLearners{3}
ans = 
  classreg.learning.classif.CompactClassificationSVM
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: [-1 1]
           ScoreTransform: '@(S)sigmoid(S,-4.016735e+00,-3.243073e-01)'
                    Alpha: [33x1 double]
                     Bias: -0.1345
         KernelParameters: [1x1 struct]
           SupportVectors: [33x4 double]
      SupportVectorLabels: [33x1 double]


  Properties, Methods

Estimate the generalization error.

genError = kfoldLoss(CVMdl)
genError = 0.0333

On average, the generalization error is approximately 3%.

Algoritmos

expandir todo

References

[1] Fürnkranz, Johannes. “Round Robin Classification.” Journal of Machine Learning Research, Vol. 2, 2002, pp. 721–747.

[2] Escalera, S., O. Pujol, and P. Radeva. “Separability of ternary codes for sparse designs of error-correcting output codes.” Pattern Recoginition Letters, Vol. 30, Issue 3, 2009, pp. 285–297.

Capacidades ampliadas

Introducido en R2014b