main content

compact multiclass model for support vector machines (svms) and other classifiers -凯发k8网页登录

compact multiclass model for support vector machines (svms) and other classifiers

description

compactclassificationecoc is 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 a compactclassificationecoc model in two ways:

  • create a compact ecoc model from a trained classificationecoc model by using the object function.

  • create a compact ecoc model by using the fitcecoc function and specifying the 'learners' name-value pair argument as 'linear', 'kernel', a templatelinear or object, or a cell array of such objects.

properties

after you create a compactclassificationecoc model object, you can use dot notation to access its properties. for an example, see train 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 in y and the coding design.

the software trains 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.

data types: cell

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

this table identifies the default binaryloss value, which depends on the score ranges returned by the binary learners.

assumptiondefault 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 by adaboostm1 or gentleboost.'exponential'
all binary learners are ensembles trained by logitboost.'binodeviance'
you specify to predict class posterior probabilities by setting 'fitposterior',true in fitcecoc.'quadratic'
binary learners are heterogeneous and use different loss functions.'hamming'

to check the default value, use dot notation to display the binaryloss property 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 the binaryloss name-value argument of predict or . for more information, see binary loss.

data types: char

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.

the elements of codingmatrix are –1, 0, and 1, and the values correspond to dichotomous class assignments. this table describes how learner j assigns observations in class i to a dichotomous class corresponding to the value of codingmatrix(i,j).

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.

data types: double | single | int8 | int16 | int32 | int64

binary learner weights, specified as a numeric row vector. the length of learnerweights is equal to the number of binary learners (length(mdl.binarylearners)).

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

the software uses learnerweights to fit posterior probabilities by minimizing the kullback-leibler divergence. the software ignores learnerweights when 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. categoricalpredictors contains index values indicating that the corresponding predictors are categorical. the index values are between 1 and p, where p is the number of predictors used to train the model. 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 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.

data types: categorical | char | logical | single | double | cell

this property is read-only.

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.

data types: double

predictor names in order of their appearance in the predictor data, specified as a cell array of character vectors. the length of predictornames is equal to the number of variables in the training data x or tbl used 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, then expandedpredictornames includes the names that describe the expanded variables. otherwise, expandedpredictornames is the same as predictornames.

data types: cell

this property is read-only.

prior class probabilities, specified as a numeric vector. prior has as many elements as the number of classes in classnames, and the order of the elements corresponds to the order of the classes in classnames.

fitcecoc incorporates 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

compare accuracies of two classification models using new data
discard support vectors of linear svm binary learners in ecoc model
classification edge for multiclass error-correcting output codes (ecoc) model
gather properties of statistics and machine learning toolbox object from gpu
convert multiclass error-correcting output codes (ecoc) model to incremental learner
limelocal interpretable model-agnostic explanations (lime)
classification loss for multiclass error-correcting output codes (ecoc) model
classification margins for multiclass error-correcting output codes (ecoc) model
partialdependencecompute partial dependence
plotpartialdependencecreate partial dependence plot (pdp) and individual conditional expectation (ice) plots
predictclassify observations using multiclass error-correcting output codes (ecoc) model
shapleyshapley values
choose subset of multiclass ecoc models composed of binary classificationlinear learners
updateupdate model parameters for code generation

examples

reduce the size of a full ecoc model by removing the training data. full ecoc models (classificationecoc models) hold the training data. to improve efficiency, use a smaller classifier.

load fisher's iris data set. specify the predictor data x, the response data y, and the order of the classes in y.

load fisheriris
x = meas;
y = categorical(species);
classorder = unique(y);

train an ecoc model using svm binary classifiers. standardize the predictor data using an svm template t, and specify the order of the classes. during training, the software uses default values for empty options in t.

t = templatesvm('standardize',true);
mdl = fitcecoc(x,y,'learners',t,'classnames',classorder);

mdl is a classificationecoc model.

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

compactmdl is a compactclassificationecoc model. compactmdl does not store all of the properties that mdl stores. 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 remove mdl from the matlab® workspace, and then pass compactmdl and new predictor values to predict.

train and cross-validate an ecoc classifier using different binary learners and the one-versus-all coding design.

load fisher's iris data set. specify the predictor data x and the response data y. determine the class names and the number of classes.

load fisheriris
x = meas;
y = species;
classnames = unique(species(~strcmp(species,''))) % remove empty classes 
classnames = 3x1 cell
    {'setosa'    }
    {'versicolor'}
    {'virginica' }
k = numel(classnames) % number of classes
k = 3

you can use classnames to specify the order of the classes during training.

for a one-versus-all coding design, this example has 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.

rng(1);  % for reproducibility
tnb = templatenaivebayes();
tsvm = templatesvm('kernelfunction','gaussian');
tlearners = {tnb tnb tsvm};

tnb and tsvm are 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.

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 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',...
    'learners',tlearners,'fitposterior',true);

cvmdl is a classificationpartitionedecoc cross-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 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 = 
  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

algorithms

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

version history

introduced in r2014b

see also

| | | | |

网站地图