Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

CompactClassificationDiscriminant

Paquete: classreg.learning.classif

Compact discriminant analysis class

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.

Construction

cobj = compact(obj) constructs a compact classifier from a full classifier.

cobj = makecdiscr(Mu,Sigma) constructs a compact discriminant analysis classifier from the class means Mu and covariance matrix Sigma. For syntax details, see makecdiscr.

Input Arguments

obj

Discriminant analysis classifier, created using fitcdiscr.

Propiedades

BetweenSigma

p-by-p matrix, the between-class covariance, where p is the number of predictors.

CategoricalPredictors

Categorical predictor indices, which is always empty ([]) .

ClassNames

List of the elements in the training data Y with duplicates removed. ClassNames can be a categorical array, cell array of character vectors, character array, logical vector, or a numeric vector. ClassNames has the same data type as the data in the argument Y. (The software treats string arrays as cell arrays of character vectors.)

Coeffs

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

  • 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.

If fitcdiscr had the FillCoeffs name-value 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 (i.e., 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.

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

Character vector specifying the discriminant type. One of:

  • '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.

Gamma

Value of the Gamma regularization parameter, a scalar from 0 to 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').

LogDetSigma

Logarithm of the determinant of the within-class covariance matrix. 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

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.

Mu

Class means, specified as a K-by-p 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.

PredictorNames

Cell array of names for the predictor variables, in the order in which they appear in the training data X.

Prior

Numeric vector of prior probabilities for each class. 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.

ResponseName

Character vector describing the response variable Y.

ScoreTransform

Character vector representing a built-in transformation function, or 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

Sigma

Within-class covariance matrix or matrices. 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

Methods

edgeClassification edge
logPLog unconditional probability density for discriminant analysis classifier
lossClassification error
mahalMahalanobis distance to class means
marginClassification margins
nLinearCoeffsNumber of nonzero linear coefficients
predictPredict labels using discriminant analysis classification model

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).

Ejemplos

contraer todo

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

       18279       11642

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'});

Más acerca de

expandir todo

Capacidades ampliadas

Introducido en R2011b