ClassificationDiscriminant - Discriminant analysis classification - MATLAB (original) (raw)

Discriminant analysis classification

Description

A ClassificationDiscriminant object encapsulates a discriminant analysis classifier, which is a Gaussian mixture model for data generation. A ClassificationDiscriminant object can predict responses for new data using the predict method. The object contains the data used for training, so can 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, specified as a p-by-p matrix, where p is the number of predictors.

Data Types: double

This property is read-only.

Data Types: struct

This property is read-only.

Data Types: double

Data Types: char | string

This property is read-only.

Data Types: double

This property is read-only.

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

Data Types: double

This property is read-only.

Parameters used in training the model, returned as aDiscriminantParams object. The returned parameters have the following properties.

Property Value
DiscrimType 'linear''quadratic''diagLinear''diagQuadratic''pseudoLinear''pseudoQuadratic'
Gamma scalar from 0 through1
Delta nonnegative scalar
FillCoeffs logical scalar
SaveMemory logical scalar
Version scalar
Method 'Discriminant'
Type 'classification'

Predictor Properties

This property is read-only.

Categorical predictor indices, which is always empty ([]).

This property is read-only.

Class means, specified 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 in the ClassNames attribute.

Data Types: double

This property is read-only.

Names of predictor variables, returned as a cell array. The names are in the order in which they appear in the training data X.

Data Types: cell

This property is read-only.

Data Types: double

This property is read-only.

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

Data Types: single | double

This property is read-only.

X data with class means subtracted, returned as a real matrix. If Y(i) is of classj,

Xcentered(i,:) =X(i,:) –Mu(j,:), (1)

where Mu is the class mean property.

Data Types: single | double

Response Properties

This property is read-only.

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

This property is read-only.

Name of the response variable Y, returned as a character vector.

Data Types: char | string

This property is read-only.

Row classifications, returned as a categorical array, cell array of character vectors, character array, logical vector, or numeric vector with the same number of rows as X. Each row ofY represents the classification of the corresponding row of X.

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

Other Data Properties

This property is read-only.

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

Data Types: char | string | function_handle

Object Functions

compact Reduce size of machine learning model
compareHoldout Compare accuracies of two classification models using new data
crossval Cross-validate machine learning model
cvshrink Cross-validate regularization of linear discriminant
edge Classification edge for discriminant analysis classifier
lime Local interpretable model-agnostic explanations (LIME)
logp Log unconditional probability density for discriminant analysis classifier
loss Classification loss for discriminant analysis classifier
mahal Mahalanobis distance to class means of discriminant analysis classifier
margin Classification margins for discriminant analysis classifier
nLinearCoeffs Number of nonzero linear coefficients in discriminant analysis classifier
partialDependence Compute partial dependence
plotPartialDependence Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots
predict Predict labels using discriminant analysis classifier
resubEdge Resubstitution classification edge for discriminant analysis classifier
resubLoss Resubstitution classification loss for discriminant analysis classifier
resubMargin Resubstitution classification margins for discriminant analysis classifier
resubPredict Classify observations in discriminant analysis classifier by resubstitution
shapley Shapley values
testckfold Compare accuracies of two classification models by repeated cross-validation

Examples

collapse all

Load Fisher's iris data set.

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. To access its properties, use dot notation. For example, display the group means for each predictor.

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 predict.

More About

expand all

The model for discriminant analysis is:

predict classifies so as to minimize the expected classification cost:

where

For details, see Prediction Using Discriminant Analysis Models.

Regularization is the process of finding a small set of predictors that yield an effective predictive model. For linear discriminant analysis, there are two parameters, γ and δ, that control regularization as follows. cvshrink helps you select appropriate values of the parameters.

Let Σ represent the covariance matrix of the data X, and let X^ be the centered data (the data X minus the mean by class). Define

The regularized covariance matrix Σ˜ is

Whenever γMinGamma, Σ˜ is nonsingular.

Let μk be the mean vector for those elements of X in class k, and let _μ_0 be the global mean vector (the mean of the rows of X). Let C be the correlation matrix of the data X, and let C˜ be the regularized correlation matrix:

where I is the identity matrix.

The linear term in the regularized discriminant analysis classifier for a data point x is

The parameter δ enters into this equation as a threshold on the final term in square brackets. Each component of the vector [C˜−1D−1/2(μk−μ0)] is set to zero if it is smaller in magnitude than the threshold δ. Therefore, for class k, if component j is thresholded to zero, component j of x does not enter into the evaluation of the posterior probability.

The DeltaPredictor property is a vector related to this threshold. When δDeltaPredictor(i), all classes k have

Therefore, when δDeltaPredictor(i), the regularized classifier does not use predictor i.

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

Version History

Introduced in R2011b

expand all

Starting in R2023b, training observations with missing predictor values are included in the X, Xcentered,Y, and W data properties. TheRowsUsed property indicates the training observations stored in the model, rather than those used for training. Observations with missing predictor values continue to be omitted from the model training process.

In previous releases, the software omitted training observations that contained missing predictor values from the data properties of the model.