Main Content

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 ClassificationDiscriminant model object by using the compact object function.

  • Create a compact model by using the makecdiscr function and specifying the class means Mu and covariance matrix Sigma.

Properties

expand all

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):

  • DiscrimType

  • Class1ClassNames(i)

  • Class2ClassNames(j)

  • Const — A scalar

  • Linear — A vector with p components, where p is the number of columns in X

  • Quadraticp-by-p matrix, exists for quadratic DiscrimType

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 1 for linear discriminant, the discriminant sets its type to 'diagLinear'.

  • If you set a value between MinGamma and 1 for linear discriminant, the discriminant sets its type to 'linear'.

  • You cannot set values below the value of the MinGamma property.

  • For quadratic discriminant, you can set either 0 (for DiscrimType 'quadratic') or 1 (for DiscrimType '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 K for quadratic discriminant analysis, where K is 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 size p-by-p, where p is the number of predictors

  • 'quadratic' — Array of size p-by-p-by-K, where K is the number of classes

  • 'diagLinear' — Row vector of length p

  • 'diagQuadratic' — Array of size 1-by-p-by-K

  • 'pseudoLinear' — Matrix of size p-by-p

  • 'pseudoQuadratic' — Array of size p-by-p-by-K

Data Types: double

Object Functions

compareHoldoutCompare accuracies of two classification models using new data
edgeClassification edge for discriminant analysis classifier
limeLocal interpretable model-agnostic explanations (LIME)
logpLog unconditional probability density for discriminant analysis classifier
lossClassification loss for discriminant analysis classifier
mahalMahalanobis distance to class means of discriminant analysis classifier
marginClassification margins for discriminant analysis classifier
nLinearCoeffsNumber of nonzero linear coefficients in discriminant analysis classifier
partialDependenceCompute partial dependence
plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
predictPredict labels using discriminant analysis classifier
shapleyShapley values

Examples

collapse all

Load the sample data.

load fisheriris

Construct 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

expand all

Extended Capabilities

Version History

Introduced in R2011b