templateDiscriminant
R2026bDiscriminant analysis classifier template
Description
returns a discriminant
analysis learner template suitable for training ensembles or error-correcting output
code (ECOC) multiclass models.t = templateDiscriminant
Specify t as a learner in fitcensemble or fitcecoc.
creates a template with additional options specified by one or more name-value
arguments. For example, you can specify the discriminant type or the regularization
parameter.t = templateDiscriminant(Name=Value)
The display of t in the Command Window
shows all configurable options as empty ([]), except those that you specify
using name-value arguments. During training, the software uses the default values for empty
options.
Examples
Create a nondefault discriminant analysis template for use in fitcensemble.
Load Fisher's iris data set.
load fisheririsCreate a template for pseudolinear discriminant analysis.
t = templateDiscriminant(DiscrimType="pseudolinear")t =
Fit template with properties:
Method: 'Discriminant'
Type: 'classification'
Configurable Options:
DiscrimType: 'pseudoLinear'
Gamma: []
Delta: []
FillCoeffs: []
SaveMemory: []
All configurable options of the template object are empty except DiscrimType. During training, the software fills in the empty options with their respective default values.
Specify t as a weak learner for a classification ensemble.
Mdl = fitcensemble(meas,species,Method="Subspace",Learners=t);Display the in-sample (resubstitution) misclassification error.
L = resubLoss(Mdl)
L = 0.0400
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: templateDiscriminant(DiscrimType="pseudoLinear",SaveMemory="on")
specifies a template for pseudolinear discriminant analysis that does not store the
full covariance matrix.
Linear coefficient threshold, specified as a nonnegative scalar value. If a coefficient of
Mdl has magnitude smaller than Delta,
Mdl sets this coefficient to 0, and 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.
Example: Delta=0.5
Data Types: single | double
Discriminant type, specified as a character vector or string scalar in this table.
| Value | Description | Predictor Covariance Treatment |
|---|---|---|
"linear" | Regularized linear discriminant analysis (LDA) |
|
"diaglinear" | LDA | All classes have the same, diagonal covariance matrix. |
"pseudolinear" | LDA | All classes have the same covariance matrix. The software inverts the covariance matrix using the pseudo inverse. |
"quadratic" | Quadratic discriminant analysis (QDA) | The covariance matrices can vary among classes. |
"diagquadratic" | QDA | The covariance matrices are diagonal and can vary among classes. |
"pseudoquadratic" | QDA | The covariance matrices can vary among classes. The software inverts the covariance matrix using the pseudo inverse. |
Note
To use regularization, you must specify "linear". To specify
the amount of regularization, use the Gamma name-value
argument.
Example: DiscrimType="quadratic"
Coeffs property flag, specified as "on" or
"off". Setting the flag to "on" populates the
Coeffs property in the classifier object. This can be
computationally intensive, especially when cross-validating. The default is
"on", unless you specify a cross-validation name-value argument,
in which case the flag is set to "off" by default.
Example: FillCoeffs="off"
Amount of regularization to apply when estimating the covariance matrix of the predictors,
specified as a scalar value in the interval [0,1]. Gamma provides
finer control over the covariance matrix structure than
DiscrimType.
If you specify
0, then the software does not use regularization to adjust the covariance matrix. That is, the software estimates and uses the unrestricted, empirical covariance matrix.For linear discriminant analysis, if the empirical covariance matrix is singular, then the software automatically applies the minimal regularization required to invert the covariance matrix. You can display the chosen regularization amount by entering
Mdl.Gammaat the command line.For quadratic discriminant analysis, if at least one class has an empirical covariance matrix that is singular, then the software throws an error.
If you specify a value in the interval (0,1), then you must implement linear discriminant analysis, otherwise the software throws an error. Consequently, the software sets
DiscrimTypeto"linear".If you specify
1, then the software uses maximum regularization for covariance matrix estimation. That is, the software restricts the covariance matrix to be diagonal. Alternatively, you can setDiscrimTypeto"diaglinear"or"diagquadratic"for diagonal covariance matrices.
Example: Gamma=1
Data Types: single | double
Flag to save covariance matrix, specified as "on" or
"off". If you specify "on", then
fitcdiscr does not store the full covariance matrix, but
instead stores enough information to compute the matrix. The predict function computes the full covariance matrix for prediction, and
does not store the matrix. If you specify "off", then
fitcdiscr computes and stores the full covariance matrix in
Mdl.
Specify SaveMemory as "on" when the input matrix
contains thousands of predictors.
Example: SaveMemory="on"
Output Arguments
Discriminant analysis classification template suitable for training ensembles or
error-correcting output code (ECOC) multiclass models, returned as a
template object. Pass t to fitcensemble or fitcecoc to specify how to
create the discriminant analysis classifier for the ensemble or ECOC model,
respectively.
If you display t in the Command Window, then all unspecified configurable
options appear empty ([]). However, the software replaces
empty options with their corresponding default values during
training.
Version History
Introduced in R2014atemplateDiscriminant returns a template object with a new display in the Command
Window. The display always includes the Method and
Type properties, as well as the configurable options that you
specify using name-value arguments in the call to templateDiscriminant.
See Also
ClassificationDiscriminant | fitcensemble | predict | fitcecoc
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)