Main Content

classificationDiscriminantComponent

Pipeline component for discriminant analysis classification

Since R2026a

    Description

    classificationDiscriminantComponent is a pipeline component that creates a discriminant analysis classifier. The pipeline component uses the functionality of the fitcdiscr function during the learn phase to train the discriminant analysis classification model. The component uses the functionality of the loss and predict functions during the run phase to perform classification.

    Creation

    Description

    component = classificationDiscriminantComponent creates a pipeline component for a discriminant analysis classification model.

    example

    component = classificationDiscriminantComponent(Name=Value) sets writable Properties using one or more name-value arguments. For example, you can specify the type of discriminant analysis, the cost of misclassification, and the observation weights.

    Properties

    expand all

    Structural Parameters

    The software sets structural parameters when you create the component. You cannot modify structural parameters after creating the component.

    This property is read-only after the component is created.

    Observation weights flag, specified as 0 (false) or 1 (true). If UseWeights is true, the component adds a third input "Weights" to the Inputs component property, and a third input tag 3 to the InputTags component property.

    Example: c = classificationDiscriminantComponent(UseWeights=1)

    Data Types: logical

    Learn Parameters

    The software sets learn parameters when you create the component. You can modify learn parameters using dot notation any time before you use the learn object function. Any unset learn parameters use the corresponding default values.

    Misclassification cost, specified as a square matrix or a structure.

    • If Cost is a square matrix, Cost(i,j) is the cost of classifying a point into class j if its true class is i.

    • If Cost is a structure S, it has two fields: S.ClassificationCosts, which contains the cost matrix; and S.ClassNames, which contains the group names and defines the class order of the rows and columns of the cost matrix.

    The default is Cost(i,j)=1 if i~=j, and Cost(i,j)=0 if i=j.

    Example: c = classificationDiscriminantComponent(Cost=[0 1; 2 0])

    Example: c.Cost = [0 2; 1 0]

    Data Types: single | double | struct

    Delta threshold for a linear discriminant model, specified as a nonnegative scalar. If the magnitude of a model coefficient is smaller than Delta, the component sets this coefficient to 0, and you can eliminate the corresponding predictor.

    Delta must be 0 when DiscrimType is "quadratic".

    Example: c = classificationDiscriminantComponent(Delta=0.1)

    Example: c.Delta = 0.2

    Data Types: single | double

    Discriminant type, specified as a value in this table.

    ValueDescriptionPredictor Covariance Treatment
    "linear"Regularized linear discriminant analysis (LDA)
    • All classes have the same covariance matrix.

    • Σ^γ=(1γ)Σ^+γdiag(Σ^).

      Σ^ is the empirical, pooled covariance matrix and γ is the amount of regularization.

    "diaglinear"LDAAll classes have the same, diagonal covariance matrix.
    "pseudolinear"LDAAll classes have the same covariance matrix. The component inverts the covariance matrix using the pseudo inverse.
    "quadratic"Quadratic discriminant analysis (QDA)The covariance matrices can vary among classes.
    "diagquadratic"QDAThe covariance matrices are diagonal and can vary among classes.
    "pseudoquadratic"QDAThe covariance matrices can vary among classes. The component inverts the covariance matrix using the pseudo inverse.

    Example: c = classificationDiscriminantComponent(DiscrimType="quadratic")

    Example: c.DiscrimType = "diagLinear"

    Data Types: char | string

    Coeffs property flag, specified as "on" or "off". Setting FillCoeffs to "on" populates the Coeffs property of TrainedModel.

    Example: c = classificationDiscriminantComponent(FillCoeffs="on")

    Example: c.FillCoeffs = "off"

    Data Types: char | string

    Amount of regularization to apply when estimating the covariance matrix of the predictors, specified as a scalar value in the interval [0,1].

    • If you specify 0, the component does not use regularization to adjust the covariance matrix. The component uses the unrestricted, empirical covariance matrix.

      • For linear discriminant analysis, if the empirical covariance matrix is singular, the component automatically applies the minimal regularization required to invert the matrix.

      • For quadratic discriminant analysis, if at least one class has a singular empirical covariance matrix, the component issues an error.

    • If you specify a value in the interval (0,1), you must specify DiscrimType as "linear", "diagLinear", or "pseudoLinear".

    • If you specify 1, the component uses maximum regularization for covariance matrix estimation. That is, the software restricts the covariance matrix to be diagonal.

    Example: c = classificationDiscriminantComponent(Gamma=1)

    Example: c.Gamma = 0

    Data Types: single | double

    Prior probabilities for each class, specified as a value in this table.

    ValueDescription
    "empirical"The class prior probabilities are the class relative frequencies. The class relative frequencies are determined by the second data argument of learn.
    "uniform"All class prior probabilities are equal to 1/K, where K is the number of classes.
    numeric vectorA numeric vector with one value for each class. Each element is a class prior probability. The component normalizes the elements such that they sum to 1.
    structure

    A structure S with two fields:

    • S.ClassNames contains a list of the class names.

    • S.ClassProbs contains a vector of corresponding prior probabilities. The component normalizes the elements such that they sum to 1.

    If you set UseWeights to true, the component renormalizes the weights to add up to the value of the prior probability in the respective class.

    Example: c = classificationDiscriminantComponent(Prior="uniform")

    Example: c.Prior = "empirical"

    Data Types: single | double | char | string | struct

    Flag to save the covariance matrix, specified as "off" or "on".

    • If you specify "on", the component does not store the covariance matrix during the learn phase. During the run phase, the component computes the full covariance matrix for prediction, and does not store the matrix.

    • If you specify "off", the component computes and stores the full covariance matrix in TrainedModel during the learn phase.

    Specify SaveMemory as "on" when the input contains thousands of predictors.

    Example: c = classificationDiscriminantComponent(SaveMemory="on")

    Example: c.SaveMemory = "off"

    Data Types: char | string

    Run Parameters

    The software sets run parameters when you create the component. You can modify the run parameters using dot notation at any time. Any unset run parameters use the corresponding default values.

    Loss function, specified as a built-in loss function name or a function handle.

    This table lists the available built-in loss functions.

    ValueDescription
    "binodeviance"Binomial deviance
    "classifcost"Observed misclassification cost
    "classiferror"Misclassified rate in decimal
    "exponential"Exponential loss
    "hinge"Hinge loss
    "logit"Logistic loss
    "mincost"Minimal expected misclassification cost (for classification scores that are posterior probabilities)
    "quadratic"Quadratic loss

    To specify a custom loss function, use function handle notation. For more information on custom loss functions, see LossFun.

    Example: c=classificationDiscriminantComponent(LossFun = "classifcost")

    Example: c.LossFun = "hinge"

    Data Types: char | string | function_handle

    Score transformation, specified as a built-in function name or a function handle.

    This table summarizes the available built-in score transform functions.

    ValueDescription
    "doublelogit"1/(1 + e–2x)
    "invlogit"log(x / (1 – x))
    "ismax"Sets the score for the class with the largest score to 1, and sets the scores for all other classes to 0
    "logit"1/(1 + ex)
    "none" or "identity"x (no transformation)
    "sign"–1 for x < 0
    0 for x = 0
    1 for x > 0
    "symmetric"2x – 1
    "symmetricismax"Sets the score for the class with the largest score to 1, and sets the scores for all other classes to –1
    "symmetriclogit"2/(1 + ex) – 1

    To specify a custom score transform function, use function handle notation. The function must accept a matrix containing the original scores and return a matrix of the same size containing the transformed scores.

    Example: c = classificationDiscriminantComponent(ScoreTransform="logit")

    Example: c.ScoreTransform = "symmetric"

    Data Types: char | string | function_handle

    Component Properties

    The software sets component properties when you create the component. You can modify the component properties (excluding HasLearnables and HasLearned) using dot notation at any time. You cannot modify the HasLearnables and HasLearned properties directly.

    Component identifier, specified as a character vector or string scalar.

    Example: c = classificationDiscriminantComponent(Name="Discriminant")

    Example: c.Name = "DiscriminantClassifier"

    Data Types: char | string

    Names of the input ports, specified as a character vector, string array, or cell array of character vectors. If UseWeights is true, the component adds the input port "Weights" to Inputs.

    Example: c = classificationDiscriminantComponent(Inputs=["X","Y"])

    Example: c.Inputs = ["In1","In2"]

    Data Types: char | string | cell

    Names of the output ports, specified as a character vector, string array, or cell array of character vectors.

    Example: c = classificationDiscriminantComponent(Outputs=["Class","ClassScore","LossVal"])

    Example: c.Outputs = ["X","Y","Z"]

    Data Types: char | string | cell

    Tags that enable the automatic connection of the component inputs with other components or pipelines, specified as a nonnegative integer vector. If you specify InputTags, the number of tags must match the number of inputs in Inputs. If UseWeights is true, the component adds a third input tag to InputTags.

    Example: c = classificationDiscriminantComponent(InputTags=[1 0])

    Example: c.InputTags = [0 1]

    Data Types: single | double

    Tags that enable the automatic connection of the component outputs with other components or pipelines, specified as a nonnegative integer vector. If you specify OutputTags, the number of tags must match the number of outputs in Outputs.

    Example: c = classificationDiscriminantComponent(OutputTags=[1 0 4])

    Example: c.OutputTags = [1 2 0]

    Data Types: single | double

    This property is read-only.

    Indicator for the learnables, returned as 1 (true). A value of 1 indicates that the component contains Learnables.

    Data Types: logical

    This property is read-only.

    Indicator showing the learning status of the component, returned as 0 (false) or 1 (true). A value of 1 indicates that the learn object function has been applied to the component, and the Learnables are nonempty.

    Data Types: logical

    Learnables

    The software sets learnables when you use the learn object function. You cannot modify learnables directly.

    This property is read-only.

    Trained model, returned as a CompactClassificationDiscriminant model object.

    Object Functions

    learnInitialize and evaluate pipeline or component
    runExecute pipeline or component for inference after learning
    resetReset pipeline or component
    seriesConnect components in series to create pipeline
    parallelConnect components or pipelines in parallel to create pipeline
    viewView diagram of pipeline inputs, outputs, components, and connections

    Examples

    collapse all

    Create a classificationDiscriminantComponent pipeline component.

    component = classificationDiscriminantComponent
    
    component = 
      classificationDiscriminantComponent with properties:
    
                Name: "ClassificationDiscriminant"
              Inputs: ["Predictors"    "Response"]
           InputTags: [1 2]
             Outputs: ["Predictions"    "Scores"    "Loss"]
          OutputTags: [1 0 0]
    
       
    Learnables (HasLearned = false)
        TrainedModel: []
    
       
    Structural Parameters (locked)
          UseWeights: 0
    
    
    Show all parameters
    

    component is a classificationDiscriminantComponent object that contains one learnable, TrainedModel. This property remains empty until you pass data to the component during the learn phase.

    To perform quadratic discriminant analysis, set the DiscrimType property of the component to "quadratic".

    component.DiscrimType = "quadratic";

    Read the fisheriris data set into a table. Store the predictor and response data in the tables X and Y, respectively.

    fisheriris = readtable("fisheriris.csv");
    X = fisheriris(:,1:end-1);
    Y = fisheriris(:,end);

    Use the learn object function to train the classificationDiscriminantComponent using the entire data set.

    component = learn(component,X,Y)
    component = 
      classificationDiscriminantComponent with properties:
    
                Name: "ClassificationDiscriminant"
              Inputs: ["Predictors"    "Response"]
           InputTags: [1 2]
             Outputs: ["Predictions"    "Scores"    "Loss"]
          OutputTags: [1 0 0]
    
       
    Learnables (HasLearned = true)
        TrainedModel: [1×1 classreg.learning.classif.CompactClassificationDiscriminant]
    
       
    Structural Parameters (locked)
          UseWeights: 0
    
       
    Learn Parameters (locked)
         DiscrimType: 'quadratic'
    
    
    Show all parameters
    

    Note that the HasLearned property is set to true, which indicates that the software trained the discriminant model TrainedModel. You can use component to classify new data using the run object function.

    Version History

    Introduced in R2026a

    See Also

    | |