CompactClassificationDiscriminant
R2026bCompact 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
ClassificationDiscriminantmodel object by using thecompactobject function.Create a compact model by using the
makecdiscrfunction and specifying the class meansMuand covariance matrixSigma.
Properties
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 typeClass1—ClassNames(i)valueClass2—ClassNames(j)valueConst— Numeric scalarLinear— Numeric vector withpcomponents, wherepis the number of columns inXQuadratic—p-by-pnumeric 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
Gammato1for a linear discriminant model, the software sets theDiscrimTypeproperty to'diagLinear'.If you set
Gammato a value betweenMinGammaand1for a linear discriminant model, the software sets theDiscrimTypeproperty to'linear'.You cannot set
Gammato a value below the value of theMinGammaproperty.For a quadratic discriminant model, you can set
Gammato0(whenDiscrimTypeis'quadratic') or1(whenDiscrimTypeis'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,
LogDetSigmais a numeric scalar.For quadratic discriminant analysis,
LogDetSigmais a numeric vector of lengthK, whereKis 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 sizep-by-p, wherepis the number of predictors'quadratic'— Array of sizep-by-p-by-K, whereKis the number of classes'diagLinear'— Row vector of lengthp'diagQuadratic'— Array of size1-by-p-by-K'pseudoLinear'— Matrix of sizep-by-p'pseudoQuadratic'— Array of sizep-by-p-by-K
Data Types: double
Object Functions
compareHoldout | Compare accuracies of two classification models using new data |
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 |
shapley | Shapley values |
Examples
Load Fisher's iris data set.
load fisheririsTrain 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
In the model for discriminant analysis, 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 the means and the covariances of each class vary.
The predict function classifies observations in a way that
minimizes 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 Prediction Using Discriminant Analysis Models.
Regularization is the process of finding a small set of predictors that yield an effective
predictive model. Linear discriminant analysis includes two parameters that control
regularization, γ and δ. 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).
The regularized covariance matrix is
When γ ≥ 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.
Extended Capabilities
Usage notes and limitations:
The
predictfunction supports code generation.When you train a discriminant analysis model by using
fitcdiscror create a compact discriminant analysis model by usingmakecdiscr, the value of theScoreTransformname-value argument cannot be an anonymous function.
For more information, see Introduction to Code Generation for Statistics and Machine Learning Functions.
Refer to the usage notes and limitations in the C/C++ Code Generation section. The same usage notes and limitations apply to GPU code generation.
Version History
Introduced in R2011b
See Also
ClassificationDiscriminant | compact | makecdiscr | fitcdiscr | predict | compareHoldout
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)