CompactClassificationDiscriminant
Compact discriminant analysis classification
Description
A CompactClassificationDiscriminant object
is a compact version of a discriminant analysis classifier. The compact version does not
include the data for training the classifier. Therefore, you cannot perform some tasks
with a compact classifier, such as cross validation. Use a compact classifier for making
predictions (classifications) of 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
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.
Categorical predictor indices, which is always empty ([]).
This property is read-only.
Class names in the training data Y with duplicates removed.
ClassNames has the same data type as the data in the argument
Y in the training data. ClassNames can have
the following data types:
Categorical array
Cell array of character vectors
Character array
Logical vector
Numeric vector
(The software treats string arrays as cell arrays of character vectors.)
Data Types: single | double | logical | char | string | cell | categorical
This property is read-only.
Coefficient matrices, specified as a k-by-k
structure, where k is the number of classes. If fitcdiscr had the FillCoeffs name-value pair set to
'off' when constructing the classifier, Coeffs
is empty ([]).
Coeffs(i,j) contains coefficients of the linear or quadratic
boundaries between classes i and j. Fields in
Coeffs(i,j):
DiscrimTypeClass1—ClassNames(i)Class2—ClassNames(j)Const— A scalarLinear— A vector withpcomponents, wherepis the number of columns inXQuadratic—p-by-pmatrix, exists for quadraticDiscrimType
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
Cost of classifying a point, specified as a square matrix.
Cost(i,j) is the cost of classifying a point into class
j if its true class is i (the rows correspond
to the true class and the columns correspond to the predicted class). The order of the
rows and columns of Cost corresponds to the order of the classes in
ClassNames. The number of rows and columns in
Cost is the number of unique classes in the response.
Change a Cost matrix using dot notation: obj.Cost =
costMatrix.
Data Types: double
Value of the Delta threshold for a linear discriminant model, specified as 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.
Data Types: double
This property is read-only.
Minimum value of Delta coefficient for predictor to be in model, specified as a row
vector of length p, where p is 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.
Data Types: double
Discriminant type, specified as a character vector or string. Available values:
'linear''quadratic''diagLinear''diagQuadratic''pseudoLinear''pseudoQuadratic'
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.
Data Types: char | string
Value of the Gamma regularization parameter, specified as a scalar from
0 through 1. Change Gamma
using dot notation: obj.Gamma = newGamma.
If you set
1for linear discriminant, the discriminant sets its type to'diagLinear'.If you set a value between
MinGammaand1for linear discriminant, the discriminant sets its type to'linear'.You cannot set values below the value of the
MinGammaproperty.For quadratic discriminant, you can set either
0(forDiscrimType'quadratic') or1(forDiscrimType'diagQuadratic').
Data Types: double
This property is read-only.
Logarithm of the determinant of the within-class covariance matrix, returned as a
scalar or vector. The type of LogDetSigma depends on the discriminant
type:
Scalar for linear discriminant analysis
Vector of length
Kfor quadratic discriminant analysis, 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.
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
Prior probabilities for each class, returned as a numeric vector. The order of the
elements of Prior corresponds to the order of the classes in
ClassNames.
Add or change a Prior vector using dot notation: obj.Prior
= priorVector.
Data Types: double
This property is read-only.
Name of the response variable Y, returned as a character
vector.
Data Types: char | string
Score transformation function, specified as a character vector or string representing
a built-in transformation function, or as a function handle for transforming scores.
'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
fitcdiscr.
Implement dot notation to add or change a ScoreTransform function
using one of the following:
cobj.ScoreTransform = 'function'cobj.ScoreTransform = @function
Data Types: char | string | function_handle
This property is read-only.
Within-class covariance, returned as a numeric array. The dimensions depend on
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 the sample data.
load fisheririsConstruct a discriminant analysis classifier for the sample data.
fullobj = fitcdiscr(meas,species);
Construct a compact discriminant analysis classifier, and compare its size to that of the full classifier.
cobj = compact(fullobj); b = whos('fullobj'); % b.bytes = size of fullobj c = whos('cobj'); % c.bytes = size of cobj [b.bytes c.bytes] % shows cobj uses 60% of the memory
ans = 1×2
19139 12328
The compact classifier is smaller than the full classifier.
Construct a compact discriminant analysis classifier from the means and covariances of the Fisher iris data.
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; cpct = makecdiscr(mu,sigstar,... 'ClassNames',{'setosa','versicolor','virginica'});
More About
The model for discriminant analysis is:
Each class (
Y) generates data (X) using a multivariate normal distribution. That is, the model assumesXhas 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 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 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.
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 the'ScoreTransform'name-value pair argument cannot be an anonymous function.
For more information, see Introduction to 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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)