Main Content

ClassificationDiscriminant

R2026b

Discriminant analysis classification

Description

ClassificationDiscriminant is a discriminant analysis classifier, which is a Gaussian mixture model for data generation. Use the predict function of ClassificationDiscriminant to predict responses for new data. Because the ClassificationDiscriminant object contains the data used for training, you can use the object to compute resubstitution predictions.

Creation

Create a ClassificationDiscriminant object by using fitcdiscr.

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

  • Class1 — ClassNames(i) value

  • Class2 — ClassNames(j) value

  • Const — Numeric scalar

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

  • Quadratic — p-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 required to make the correlation matrix invertible, returned as a nonnegative scalar. If the correlation matrix is not singular, MinGamma is 0.

Data Types: double

This property is read-only.

Parameters used to train the model, returned as a DiscriminantParams object with the following properties.

PropertyValue
DiscrimType
  • 'linear'

  • 'quadratic'

  • 'diagLinear'

  • 'diagQuadratic'

  • 'pseudoLinear'

  • 'pseudoQuadratic'

Gammascalar from 0 through 1
Deltanonnegative scalar
FillCoeffslogical scalar
SaveMemorylogical scalar
Versionscalar
Method'Discriminant'
Type'classification'

Predictor Properties

This property is read-only.

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

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

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

This property is read-only.

Predictor values, returned as a real matrix. Each column of X represents one predictor (variable), and each row represents one observation.

Data Types: single | double

This property is read-only.

X data with the class means subtracted, returned as a real matrix. If Y(i) is of class j, Xcentered(i,:) = X(i,:) – Mu(j,:), where Mu is the class means property.

Data Types: single | double

Response Properties

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

This property is read-only.

Response variable name, returned as a character vector.

Data Types: char

This property is read-only.

Class labels used to train the model, returned as a numeric vector, categorical vector, logical vector, character array, or cell array of character vectors. Y has the same data type as the response variable used to train the model. (The software treats string arrays as cell arrays of character vectors.)

Each row of Y represents the classification of the corresponding observation in X.

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

Other Data Properties

This property is read-only.

Cross-validation optimization of hyperparameters, returned as a SupervisedLearningBayesianOptimization object or a table of hyperparameters and associated values. This property is nonempty if the OptimizeHyperparameters name-value argument is nonempty when you create the model. The value of HyperparameterOptimizationResults depends on the setting of the Optimizer option in the HyperparameterOptimizationOptions value when you create the model.

Value of Optimizer OptionValue of HyperparameterOptimizationResults
"bayesopt" (default)SupervisedLearningBayesianOptimization object
"gridsearch" or "randomsearch"Table of hyperparameters used, observed objective function values (cross-validation loss), and observation ranks from lowest (best) to highest (worst)

This property is read-only.

Number of observations in the training data, returned as a positive integer. NumObservations can be less than the number of rows of input data when there are missing values in the input data or response data.

Data Types: double

This property is read-only.

Rows of the original predictor data X used for fitting, returned as an n-element logical vector, where n is the number of rows of X. If the software uses all rows of X to create the object, then RowsUsed is an empty array ([]).

Data Types: logical

This property is read-only.

Scaled observation weights, returned as a numeric vector of length n, where n is the number of rows in X.

Data Types: double

Other Classification Properties

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

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

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

Object Functions

compactReduce size of machine learning model
compareHoldoutCompare accuracies of two classification models using new data
crossvalCross-validate machine learning model
cvshrinkCross-validate regularization of linear discriminant
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
resubEdgeResubstitution classification edge for discriminant analysis classifier
resubLossResubstitution classification loss for discriminant analysis classifier
resubMarginResubstitution classification margins for discriminant analysis classifier
resubPredictClassify observations in discriminant analysis classifier by resubstitution
shapleyShapley values
testckfoldCompare accuracies of two classification models by repeated cross-validation

Examples

collapse all

Load Fisher's iris data set.

load fisheriris

Train a discriminant analysis model using the entire data set.

Mdl = fitcdiscr(meas,species)
Mdl = 
  ClassificationDiscriminant
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'setosa'  'versicolor'  'virginica'}
           ScoreTransform: 'none'
          NumObservations: 150
              DiscrimType: 'linear'
                       Mu: [3×4 double]
                   Coeffs: [3×3 struct]


  Properties, Methods

Mdl is a ClassificationDiscriminant model object. To access its properties, use dot notation. For example, display the class means for each predictor.

Mdl.Mu
ans = 3×4

    5.0060    3.4280    1.4620    0.2460
    5.9360    2.7700    4.2600    1.3260
    6.5880    2.9740    5.5520    2.0260

To predict labels for new observations, pass Mdl and predictor data to the predict function.

More About

expand all

References

[1] Guo, Y., T. Hastie, and R. Tibshirani. "Regularized Linear Discriminant Analysis and Its Application in Microarrays." Biostatistics, Vol. 8, No. 1, pp. 86–100, 2007.

Extended Capabilities

expand all

Version History

Introduced in R2011b

expand all