Categories &

Functions List

Class Definition: CompactClassificationDiscriminant

statistics: CompactClassificationDiscriminant

A CompactClassificationDiscriminant object is a compact version of a discriminant analysis model, ClassificationDiscriminant.

The CompactClassificationDiscriminant does not include the training data resulting to a smaller classifier size, which can be used for making predictions from new data, but not for tasks such as cross validation. It can only be created from a ClassificationDiscriminant model by using the compact object method.

The available methods for a CompactClassificationDiscriminant object are:

  • predict
  • loss
  • margin
  • savemodel

See also: fitcdiscr, compact, ClassificationDiscriminant

Source Code: CompactClassificationDiscriminant

Method: loss

CompactClassificationDiscriminant: L = loss (obj, X, Y)
CompactClassificationDiscriminant: L = loss (…, name, value)

Compute loss for a trained CompactClassificationDiscriminant object.

L = loss (obj, X, Y) computes the loss, L, using the default loss function 'mincost'.

  • obj is a CompactClassificationDiscriminant object trained on X and Y.
  • X must be a N×P numeric matrix of input data where rows correspond to observations and columns correspond to features or variables.
  • Y is N×1 matrix or cell matrix containing the class labels of corresponding predictor data in X. Y must have same numbers of Rows as X.

L = loss (…, name, value) allows additional options specified by name-value pairs:

NameValue
"LossFun"Specifies the loss function to use. Can be a function handle with four input arguments (C, S, W, Cost) which returns a scalar value or one of: ’binodeviance’, ’classifcost’, ’classiferror’, ’exponential’, ’hinge’, ’logit’,’mincost’, ’quadratic’.
  • C is a logical matrix of size N×K, where N is the number of observations and K is the number of classes. The element C(i,j) is true if the class label of the i-th observation is equal to the j-th class.
  • S is a numeric matrix of size N×K, where each element represents the classification score for the corresponding class.
  • W is a numeric vector of length N, representing the observation weights.
  • Cost is a K×K matrix representing the misclassification costs.
"Weights"Specifies observation weights, must be a numeric vector of length equal to the number of rows in X. Default is ones (size (X, 1)). loss normalizes the weights so that observation weights in each class sum to the prior probability of that class. When you supply Weights, loss computes the weighted classification loss.

See also: CompactClassificationDiscriminant

Method: margin

CompactClassificationDiscriminant: m = margin (obj, X, Y)

m = margin (obj, X, Y) returns the classification margins for obj with data X and classification Y. m is a numeric vector of length size (X,1).

  • obj is a CompactClassificationDiscriminant object trained on X and Y.
  • X must be a N×P numeric matrix of input data where rows correspond to observations and columns correspond to features or variables.
  • Y is N×1 matrix or cell matrix containing the class labels of corresponding predictor data in X. Y must have same numbers of Rows as X.

The classification margin for each observation is the difference between the classification score for the true class and the maximal classification score for the false classes.

See also: fitcdiscr, CompactClassificationDiscriminant

Method: predict

CompactClassificationDiscriminant: label = predict (obj, XC)
CompactClassificationDiscriminant: [label, score, cost] = predict (obj, XC)

Classify new data points into categories using the discriminant analysis model from a CompactClassificationDiscriminant object.

label = predict (obj, XC) returns the vector of labels predicted for the corresponding instances in XC, using the corresponding labels from the trained ClassificationDiscriminant, model, obj.

  • obj must be a CompactClassificationDiscriminant class object.
  • XC must be an M×P numeric matrix with the same number of features P as the corresponding predictors of the discriminant model in obj.

[label, score, cost] = predict (obj, XC) also returns score, which contains the predicted class scores or posterior probabilities for each instance of the corresponding unique classes, and cost, which is a matrix containing the expected cost of the classifications.

The score matrix contains the posterior probabilities for each class, calculated using the multivariate normal probability density function and the prior probabilities of each class. These scores are normalized to ensure they sum to 1 for each observation.

The cost matrix contains the expected classification cost for each class, computed based on the posterior probabilities and the specified misclassification costs.

See also: CompactClassificationDiscriminant, fitcdiscr

Method: savemodel

CompactClassificationDiscriminant: savemodel (obj, filename)

Save a CompactClassificationDiscriminant object.

savemodel (obj, filename) saves a CompactClassificationDiscriminant object into a file defined by filename.

See also: loadmodel, fitcdiscr, CompactClassificationDiscriminant

Example: 1

 

 ## Create a discriminant analysis classifier and its compact version
 # and compare their size

 load fisheriris
 X = meas;
 Y = species;

 Mdl = fitcdiscr (X, Y, 'ClassNames', unique (species))
 CMdl = crossval (Mdl);

 whos ('Mdl', 'CMdl')

Mdl =

  ClassificationDiscriminant object with properties:

           ClassNames: [3x1 cell]
               Coeffs: [3x3 struct]
                 Cost: [3x3 double]
                Delta: [1x1 double]
          DiscrimType: linear
                Gamma: [1x1 double]
          LogDetSigma: [1x1 double]
             MinGamma: [1x1 double]
                   Mu: [3x4 double]
      NumObservations: [1x1 double]
        NumPredictors: [1x1 double]
       PredictorNames: [1x4 cell]
                Prior: [3x1 double]
         ResponseName: Y
             RowsUsed: [150x1 double]
       ScoreTransform: none
                Sigma: [4x4 double]
                    X: [150x4 double]
            XCentered: [150x4 double]
                    Y: [150x1 cell]

Variables visible from the current scope:

variables in scope: build_DEMOS: /home/promitheas/.local/share/octave/api-v59/packages/pkg-octave-doc-0.5.5/build_DEMOS.m

  Attr   Name        Size                     Bytes  Class
  ====   ====        ====                     =====  ===== 
         Mdl         1x1                          0  ClassificationDiscriminant
         CMdl        1x1                          0  ClassificationPartitionedModel

Total is 2 elements using 0 bytes