Main Content

CompactClassificationECOC

Compact multiclass model for support vector machines (SVMs) and other classifiers

Description

CompactClassificationECOCis a compact version of the multiclass error-correcting output codes (ECOC) model. The compact classifier does not include the data used for training the multiclass ECOC model. Therefore, you cannot perform certain tasks, such as cross-validation, using the compact classifier. Use a compact multiclass ECOC model for tasks such as classifying new data (predict).

Creation

You can create aCompactClassificationECOCmodel in two ways:

  • Create a compact ECOC model from a trainedClassificationECOCmodel by using thecompactobject function.

  • Create a compact ECOC model by using thefitcecocfunction and specifying the“学习者”name-value pair argument as'linear','kernel', atemplateLinearortemplateKernelobject, or a cell array of such objects.

Properties

expand all

After you create aCompactClassificationECOCmodel object, you can use dot notation to access its properties. For an example, seeTrain and Cross-Validate ECOC Classifier.

ECOC Properties

Trained binary learners, specified as a cell vector of model objects. The number of binary learners depends on the number of classes inYand the coding design.

The software trainsBinaryLearner{j}according to the binary problem specified byCodingMatrix(:,j). For example, for multiclass learning using SVM learners, each element ofBinaryLearnersis aCompactClassificationSVMclassifier.

Data Types:cell

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

This table identifies the defaultBinaryLossvalue, which depends on the score ranges returned by the binary learners.

Assumption Default Value

All binary learners are any of the following:

  • Classification decision trees

  • Discriminant analysis models

  • k-nearest neighbor models

  • Linear or kernel classification models of logistic regression learners

  • Naive Bayes models

'quadratic'
All binary learners are SVMs or linear or kernel classification models of SVM learners. 'hinge'
All binary learners are ensembles trained byAdaboostM1orGentleBoost. 'exponential'
All binary learners are ensembles trained byLogitBoost. 'binodeviance'
You specify to predict class posterior probabilities by setting'FitPosterior',trueinfitcecoc. 'quadratic'
Binary learners are heterogeneous and use different loss functions. “汉明”

To check the default value, use dot notation to display theBinaryLossproperty of the trained model at the command line.

To potentially increase accuracy, specify a binary loss function other than the default during a prediction or loss computation by using theBinaryLossname-value argument ofpredictorloss. For more information, seeBinary Loss.

Data Types:char

Class assignment codes for the binary learners, specified as a numeric matrix.CodingMatrixis aK-by-Lmatrix, whereKis the number of classes andLis the number of binary learners.

The elements ofCodingMatrixare–1,0, and1, and the values correspond to dichotomous class assignments. This table describes how learnerjassigns observations in classito a dichotomous class corresponding to the value ofCodingMatrix(i,j).

Value Dichotomous Class Assignment
–1 Learnerjassigns observations in classito a negative class.
0 Before training, learnerjremoves observations in classifrom the data set.
1 Learnerjassigns observations in classito a positive class.

Data Types:double|single|int8|int16|int32|int64

Binary learner weights, specified as a numeric row vector. The length ofLearnerWeightsis equal to the number of binary learners (length(Mdl.BinaryLearners)).

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

The software usesLearnerWeightsto fit posterior probabilities by minimizing the Kullback-Leibler divergence. The software ignoresLearnerWeightswhen it uses the quadratic programming method of estimating posterior probabilities.

Data Types:double|single

Other Classification Properties

Categorical predictor indices, specified as a vector of positive integers.CategoricalPredictorscontains index values indicating that the corresponding predictors are categorical. The index values are between 1 andp, wherep预测的数量被用来训练模式l. If none of the predictors are categorical, then this property is empty ([]).

Data Types: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有the same data type as the class labelsY.(The software treats string arrays as cell arrays of character vectors.)ClassNamesalso determines the class order.

Data Types:categorical|char|logical|single|double|cell

This property is read-only.

Misclassification costs, specified as a square numeric matrix.CostKrows and columns, whereKis the number of classes.

Cost(i,j)is the cost of classifying a point into classjif its true class isi. The order of the rows and columns ofCostcorresponds to the order of the classes inClassNames.

Data Types:double

Predictor names in order of their appearance in the predictor data, specified as a cell array of character vectors. The length ofPredictorNamesis equal to the number of variables in the training dataXorTblused as predictor variables.

Data Types:cell

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

If the model uses encoding for categorical variables, thenExpandedPredictorNamesincludes the names that describe the expanded variables. Otherwise,ExpandedPredictorNamesis the same asPredictorNames.

Data Types:cell

This property is read-only.

Prior class probabilities, specified as a numeric vector.Prior有as many elements as the number of classes inClassNames, and the order of the elements corresponds to the order of the classes inClassNames.

fitcecocincorporates misclassification costs differently among different types of binary learners.

Data Types:double

Response variable name, specified as a character vector.

Data Types:char

This property is read-only.

Score transformation function to apply to the predicted scores, specified as'none'. An ECOC model does not support score transformation.

Object Functions

compareHoldout Compare accuracies of two classification models using new data
discardSupportVectors Discard support vectors of linear SVM binary learners in ECOC model
edge Classification edge for multiclass error-correcting output codes (ECOC) model
gather Gather properties ofStatistics and Machine Learning Toolboxobject from GPU
incrementalLearner Convert multiclass error-correcting output codes (ECOC) model to incremental learner
lime Local interpretable model-agnostic explanations (LIME)
loss Classification loss for multiclass error-correcting output codes (ECOC) model
margin Classification margins for multiclass error-correcting output codes (ECOC) model
partialDependence Compute partial dependence
plotPartialDependence Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots
predict Classify observations using multiclass error-correcting output codes (ECOC) model
shapley Shapley values
selectModels Choose subset of multiclass ECOC models composed of binaryClassificationLinearlearners
update Update model parameters for code generation

Examples

collapse all

Reduce the size of a full ECOC model by removing the training data. Full ECOC models (ClassificationECOCmodels) hold the training data. To improve efficiency, use a smaller classifier.

Load Fisher's iris data set. Specify the predictor dataX, the response dataY和类的顺序Y.

loadfisheririsX = meas; Y = categorical(species); classOrder = unique(Y);

Train an ECOC model using SVM binary classifiers. Standardize the predictor data using an SVM templatet, and specify the order of the classes. During training, the software uses default values for empty options int.

t = templateSVM('Standardize',true); Mdl = fitcecoc(X,Y,“学习者”,t,'ClassNames',classOrder);

Mdlis aClassificationECOCmodel.

Reduce the size of the ECOC model.

CompactMdl = compact(Mdl)
CompactMdl = CompactClassificationECOC ResponseName: 'Y' CategoricalPredictors: [] ClassNames: [setosa versicolor virginica] ScoreTransform: 'none' BinaryLearners: {3x1 cell} CodingMatrix: [3x3 double] Properties, Methods

CompactMdlis aCompactClassificationECOCmodel.CompactMdldoes not store all of the properties thatMdlstores. In particular, it does not store the training data.

Display the amount of memory each classifier uses.

whos('CompactMdl','Mdl')
Name Size Bytes Class Attributes CompactMdl 1x1 15116 classreg.learning.classif.CompactClassificationECOC Mdl 1x1 28357 ClassificationECOC

The full ECOC model (Mdl) is approximately double the size of the compact ECOC model (CompactMdl).

To label new observations efficiently, you can removeMdlfrom the MATLAB® Workspace, and then passCompactMdland new predictor values topredict.

火车和旨在ECOC分类器使用different binary learners and the one-versus-all coding design.

Load Fisher's iris data set. Specify the predictor dataXand the response dataY. Determine the class names and the number of classes.

loadfisheririsX = meas; Y = species; classNames = unique(species(~strcmp(species,'')))% Remove empty classes
classNames =3x1 cell{'setosa' } {'versicolor'} {'virginica' }
K = numel(classNames)%的数量classes
K = 3

You can useclassNamesto specify the order of the classes during training.

For a one-versus-all coding design, this example hasK= 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.

rng(1);% For reproducibilitytNB = templateNaiveBayes(); tSVM = templateSVM('KernelFunction','gaussian'); tLearners = {tNB tNB tSVM};

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

火车和旨在ECOC分类器使用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 distances from the decision boundary. Therefore, to aggregate the binary learners, you must specify to fit posterior probabilities.

CVMdl = fitcecoc(X,Y,'ClassNames',classNames,'CrossVal','on',...“学习者”,tLearners,'FitPosterior',true);

CVMdlis aClassificationPartitionedECOCcross-validated model. By default, the software implements 10-fold cross-validation. The scores across the binary learners have 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 = CompactClassificationECOC ResponseName: 'Y' CategoricalPredictors: [] ClassNames: {'setosa' 'versicolor' 'virginica'} ScoreTransform: 'none' BinaryLearners: {3x1 cell} CodingMatrix: [3x3 double] Properties, Methods

Each fold is aCompactClassificationECOCmodel 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 = CompactClassificationSVM ResponseName: 'Y' CategoricalPredictors: [] ClassNames: [-1 1] ScoreTransform: '@(S)sigmoid(S,-4.016619e+00,-3.243499e-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%.

More About

expand all

Algorithms

expand all

References

[1] Fürnkranz, Johannes. “Round Robin Classification.”J. Mach. Learn. Res., 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 Recog. Lett., Vol. 30, Issue 3, 2009, pp. 285–297.

Extended Capabilities

他的版本tory

Introduced in R2014b

Baidu
map