Documentation Center 
Superclasses: CompactClassificationDiscriminant
Discriminant analysis classification
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.
obj = fitcdiscr(x,y) creates a discriminant classification object based on the input variables (also known as predictors, features, or attributes) x and output (response) y. For syntax details, see fitcdiscr.
obj = fitcdiscr(x,y,Name,Value) creates a classifier with additional options specified by one or more Name,Value pair arguments. If you use one of the following five options, obj is of class ClassificationPartitionedModel: 'CrossVal', 'KFold', 'Holdout', 'Leaveout', or 'CVPartition'. Otherwise, obj is of class ClassificationDiscriminant.
x 
Matrix of numeric predictor values. Each column of x represents one variable, and each row represents one observation. NaN values in x are considered missing values. Observations with missing values for x are not used in the fit. 
y 
A categorical array, cell array of strings, character array, logical vector, or a numeric vector with the same number of rows as x. Each row of y represents the classification of the corresponding row of x. NaN values in y are considered missing values. Observations with missing values for y are not used in the fit. 
BetweenSigma 
pbyp matrix, the betweenclass covariance, where p is the number of predictors. 
CategoricalPredictors 
List of categorical predictors, which is always empty ([]) for SVM and discriminant analysis classifiers. 
ClassNames 
List of the elements in the training data Y with duplicates removed. ClassNames can be a categorical array, cell array of strings, character array, logical vector, or a numeric vector. ClassNames has the same data type as the data in the argument Y. 
Coeffs 
kbyk structure of coefficient matrices, where k is the number of classes. Coeffs(i,j) contains coefficients of the linear or quadratic boundaries between classes i and j. Fields in Coeffs(i,j):
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. If fitcdiscr had the FillCoeffs namevalue pair set to 'off' when constructing the classifier, Coeffs is empty ([]). 
Cost 
Square matrix, where Cost(i,j) is the cost of classifying a point into class j if its true class is i. Cost is KbyK, where K is the number of classes. Change a Cost matrix using dot notation: obj.Cost = costMatrix. 
Delta 
Value of the Delta threshold for a linear discriminant model, a nonnegative scalar. If a coefficient of obj has magnitude smaller than Delta, obj sets this coefficient to 0, and so you can eliminate the corresponding predictor from the model. Set Delta to a higher value to eliminate more predictors. Delta must be 0 for quadratic discriminant models. Change Delta using dot notation: obj.Delta = newDelta. 
DeltaPredictor 
Row vector of length equal to the number of predictors in obj. If DeltaPredictor(i) < Delta then coefficient i of the model is 0. If obj is a quadratic discriminant model, all elements of DeltaPredictor are 0. 
DiscrimType 
String specifying the discriminant type. One of:
Change DiscrimType using dot notation: obj.DiscrimType = newDiscrimType. You can change between linear types, or between quadratic types, but cannot change between linear and quadratic types. 
Gamma 
Value of the Gamma regularization parameter, a scalar from 0 to 1. Change Gamma using dot notation: obj.Gamma = newGamma.

LogDetSigma 
Logarithm of the determinant of the withinclass covariance matrix. The type of LogDetSigma depends on the discriminant type:

MinGamma 
Nonnegative scalar, the minimal value of the Gamma parameter so that the correlation matrix is invertible. If the correlation matrix is not singular, MinGamma is 0. 
ModelParameters 
Parameters used in training obj. 
Mu 
Class means, specified as a Kbyp matrix of scalar values class means of size. 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. 
NumObservations 
Number of observations in the training data, a numeric scalar. NumObservations can be less than the number of rows of input data X when there are missing values in X or response Y. 
PredictorNames 
Cell array of names for the predictor variables, in the order in which they appear in the training data X. 
Prior 
Prior probabilities for each class. Prior is a numeric vector whose entries relate to the corresponding ClassNames property. Add or change a Prior vector using dot notation: obj.Prior = priorVector. 
ResponseName 
String describing the response variable Y. 
ScoreTransform 
Function handle for transforming scores, or string representing a builtin transformation function. 'none' means no transformation; equivalently, 'none' means @(x)x. For a list of builtin transformation functions and the syntax of custom transformation functions, see fitcdiscr. Implement dot notation to add or change a ScoreTransform function using one of the following:

Sigma 
Withinclass covariance matrix or matrices. The dimensions depend on DiscrimType:

W 
Scaled weights, a vector with length n, the number of rows in X. 
X 
Matrix of predictor values. Each column of X represents one predictor (variable), and each row represents one observation. 
Xcentered 
X data with class means subtracted. If Y(i) is of class j, Xcentered(i,:) = X(i,:) – Mu(j,:), where Mu is the class mean property. 
Y 
A categorical array, cell array of strings, character array, logical vector, or a numeric vector with the same number of rows as X. Each row of Y represents the classification of the corresponding row of X. 
compact  Compact discriminant analysis classifier 
crossval  Crossvalidated discriminant analysis classifier 
cvshrink  Crossvalidate regularization of linear discriminant 
resubEdge  Classification edge by resubstitution 
resubLoss  Classification error by resubstitution 
resubMargin  Classification margins by resubstitution 
resubPredict  Predict resubstitution response of classifier 
edge  Classification edge 
logP  Log of the unconditional probability density 
loss  Classification error 
mahal  Mahalanobis distance to class means 
margin  Classification margins 
nLinearCoeffs  Number of nonzero linear coefficients 
predict  Predict classification 
The model for discriminant analysis is:
Each class (Y) generates data (X) using a multivariate normal distribution. That is, the model assumes X has a Gaussian mixture distribution (gmdistribution).
For linear discriminant analysis, the model has the same covariance matrix for each class, only the means vary.
For quadratic discriminant analysis, both means and covariances of each class vary.
predict classifies so as to minimize the expected classification cost:
where
is the predicted classification.
K is the number of classes.
is the posterior probability of class k for observation x.
is the cost of classifying an observation as y when its true class is k.
For details, see How the predict Method Classifies.
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 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 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 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.
Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB^{®} documentation.
Create a discriminant analysis classifier for the Fisher iris data:
load fisheriris obj = fitcdiscr(meas,species) obj = ClassificationDiscriminant: PredictorNames: {'x1' 'x2' 'x3' 'x4'} ResponseName: 'Y' ClassNames: {'setosa' 'versicolor' 'virginica'} ScoreTransform: 'none' NumObservations: 150 DiscrimType: 'linear' Mu: [3x4 double] Coeffs: [3x3 struct]
[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.
CompactClassificationDiscriminant  fitcdiscr