Main Content

CompactClassificationDiscriminant

R2026b

Compact discriminant analysis classification

Description

CompactClassificationDiscriminant is a compact version of a discriminant analysis classifier. The compact version does not include the data used to train the classifier. Therefore, you cannot perform some tasks, such as cross-validation, using the compact classifier. Use a compact classifier to make predictions (classifications) for new data.

Creation

You can create a CompactClassificationDiscriminant object in two ways:

  • Create a compact model from a full ClassificationDiscriminant model object by using the compact object function.

  • Create a compact model by using the makecdiscr function and specifying the class means Mu and covariance matrix Sigma.

Properties

expand all

Discriminant Analysis Properties

This property is read-only.

Between-class covariance, returned as a p-by-p matrix, where p is the number of predictors.

Data Types: double

This property is read-only.

Coefficient matrices, returned as a k-by-k structure, where k is the number of classes. If the value of the FillCoeffs name-value argument is "off" when you create the classifier object, Coeffs is empty ([]).

Coeffs(i,j) contains the coefficients of the linear or quadratic boundaries between classes i and j. The fields in Coeffs(i,j) are:

  • DiscrimType — Character vector corresponding to the discriminant type

  • Class1ClassNames(i) value

  • Class2ClassNames(j) value

  • Const — Numeric scalar

  • Linear — Numeric vector with p components, where p is the number of columns in X

  • Quadraticp-by-p numeric matrix. This field exists only when the discriminant type is quadratic.

The equation of the boundary between class i and class j is

Const + Linear * x + x' * Quadratic * x = 0,

where x is a column vector of length p.

Data Types: struct

Delta threshold for a linear discriminant model, specified as a nonnegative scalar. If a coefficient of the classifier object has a magnitude smaller than Delta, the software sets the coefficient to 0, which means you can remove the corresponding predictor from the model. Set Delta to a higher value to remove more predictors.

Delta must be 0 for quadratic discriminant models.

To change the value of Delta to newDelta for a classifier object Mdl, you can use dot notation: Mdl.Delta = newDelta.

Data Types: double

This property is read-only.

Minimum value of the Delta coefficient needed for the predictor to be included in the model, returned as a row vector of length p, where p is the number of predictors in the classifier object. If DeltaPredictor(i) < Delta, then coefficient i of the model is 0.

If the classifier is a quadratic discriminant model, all elements of DeltaPredictor are 0.

Data Types: double

Discriminant type, specified as a character vector or string scalar corresponding to one of these values:

  • "linear"

  • "quadratic"

  • "diagLinear"

  • "diagQuadratic"

  • "pseudoLinear"

  • "pseudoQuadratic"

To change the value of DiscrimType to newDiscrimType for a classifier object Mdl, you can use dot notation: Mdl.DiscrimType = newDiscrimType. You can change one linear type to another, or one quadratic type to another, but cannot change a linear type to a quadratic type (or vice versa).

Data Types: char | string

Gamma regularization parameter, specified as a scalar from 0 through 1. To change the Gamma value to newGamma for a classifier object Mdl, you can use dot notation: Mdl.Gamma = newGamma.

  • If you set Gamma to 1 for a linear discriminant model, the software sets the DiscrimType property to 'diagLinear'.

  • If you set Gamma to a value between MinGamma and 1 for a linear discriminant model, the software sets the DiscrimType property to 'linear'.

  • You cannot set Gamma to a value below the value of the MinGamma property.

  • For a quadratic discriminant model, you can set Gamma to 0 (when DiscrimType is 'quadratic') or 1 (when DiscrimType is 'diagQuadratic').

Data Types: double

This property is read-only.

Logarithm of the determinant of the within-class covariance matrix, returned as a numeric scalar or numeric vector.

  • For linear discriminant analysis, LogDetSigma is a numeric scalar.

  • For quadratic discriminant analysis, LogDetSigma is a numeric vector of length K, where K is the number of classes.

Data Types: double

This property is read-only.

Minimal value of the Gamma parameter so that the correlation matrix is invertible, returned as a nonnegative scalar. If the correlation matrix is not singular, MinGamma is 0.

Data Properties

This property is read-only.

Categorical predictor indices, returned as an empty array [].

This property is read-only.

Unique class names used in training, returned as a numeric vector, categorical vector, logical vector, character array, 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: single | double | categorical | logical | char | cell

Misclassification costs, returned 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.

To change the value of Cost to costMatrix for a classifier object Mdl, you can use dot notation: Mdl.Cost = costMatrix.

Data Types: double

This property is read-only.

Class means, returned as a K-by-p matrix of real values. K is the number of classes, and p is the number of predictors. Each row of Mu represents the mean of the multivariate normal distribution of the corresponding class. The class indices are stored in the ClassNames property.

Data Types: double

This property is read-only.

Predictor variable names, returned as a cell array of character vectors. The order of the elements in PredictorNames corresponds to the order in which the predictor names appear in the training data.

Data Types: cell

Prior probabilities for each class, returned as a K-element numeric vector, where K is the number of unique classes in the response. The order of the elements of Prior corresponds to the order of the classes in ClassNames.

To change the value of Prior to priorVector for a classifier object Mdl, you can use dot notation: Mdl.Prior = priorVector.

Data Types: double

This property is read-only.

Response variable name, returned as a character vector.

Data Types: char

Function for transforming scores, specified as a function handle or the name of a built-in transformation function. "none" means no transformation; equivalently, "none" means @(x)x. For a list of built-in transformation functions and the syntax of custom transformation functions, see ScoreTransform.

To change the value of ScoreTransform for a classifier object Mdl, you can use dot notation:

Mdl.ScoreTransform = "function"
% or
Mdl.ScoreTransform = @function

Data Types: char | string | function_handle

This property is read-only.

Within-class covariance, returned as a numeric array. The dimensions of the array depend on the value of DiscrimType:

  • 'linear' (default) — Matrix of size p-by-p, where p is the number of predictors

  • 'quadratic' — Array of size p-by-p-by-K, where K is the number of classes

  • 'diagLinear' — Row vector of length p

  • 'diagQuadratic' — Array of size 1-by-p-by-K

  • 'pseudoLinear' — Matrix of size p-by-p

  • 'pseudoQuadratic' — Array of size p-by-p-by-K

Data Types: double

Object Functions

compareHoldoutCompare accuracies of two classification models using new data
edgeClassification edge for discriminant analysis classifier
limeLocal interpretable model-agnostic explanations (LIME)
logpLog unconditional probability density for discriminant analysis classifier
lossClassification loss for discriminant analysis classifier
mahalMahalanobis distance to class means of discriminant analysis classifier
marginClassification margins for discriminant analysis classifier
nLinearCoeffsNumber of nonzero linear coefficients in discriminant analysis classifier
partialDependenceCompute partial dependence
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
predictPredict labels using discriminant analysis classifier
shapleyShapley values

Examples

collapse all

Load Fisher's iris data set.

load fisheriris

Train a discriminant analysis classifier using the entire data set.

Mdl = fitcdiscr(meas,species);

Reduce the size of the discriminant analysis classifier.

CMdl = compact(Mdl)
CMdl = 
  CompactClassificationDiscriminant
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'setosa'  'versicolor'  'virginica'}
           ScoreTransform: 'none'
              DiscrimType: 'linear'
                       Mu: [3×4 double]
                   Coeffs: [3×3 struct]


  Properties, Methods

CMdl is a trained CompactClassificationDiscriminant classifier.

Display the amount of memory used by each classifier.

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

  CMdl      1x1             12328  classreg.learning.classif.CompactClassificationDiscriminant              
  Mdl       1x1             19139  ClassificationDiscriminant                                               

The compact classifier (CMdl) is smaller than the full classifier (Mdl).

Create a compact discriminant analysis classifier from the means and covariances of the Fisher iris data set.

load fisheriris

mu(1,:) = mean(meas(1:50,:));
mu(2,:) = mean(meas(51:100,:));
mu(3,:) = mean(meas(101:150,:));

mm1 = repmat(mu(1,:),50,1);
mm2 = repmat(mu(2,:),50,1);
mm3 = repmat(mu(3,:),50,1);

cc = meas;
cc(1:50,:) = cc(1:50,:) - mm1;
cc(51:100,:) = cc(51:100,:) - mm2;
cc(101:150,:) = cc(101:150,:) - mm3;
sigstar = cc' * cc / 147;

compactMdl = makecdiscr(mu,sigstar, ...
    ClassNames=["setosa","versicolor","virginica"])
compactMdl = 
  CompactClassificationDiscriminant
           PredictorNames: {'x1'  'x2'  'x3'  'x4'}
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'setosa'  'versicolor'  'virginica'}
           ScoreTransform: 'none'
              DiscrimType: 'linear'
                       Mu: [3×4 double]
                   Coeffs: [3×3 struct]


  Properties, Methods

More About

expand all

Extended Capabilities

expand all

Version History

Introduced in R2011b