# makecdiscr

Construct discriminant analysis classifier from parameters

## Syntax

``cobj = makecdiscr(Mu,Sigma)``
``cobj = makecdiscr(Mu,Sigma,Name,Value)``

## Description

example

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

example

````cobj = makecdiscr(Mu,Sigma,Name,Value)` constructs a compact classifier with additional options specified by one or more name-value pair arguments. For example, you can specify the cost of misclassification or the prior probabilities for each class.```

## Examples

collapse all

Construct a compact linear 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; % unbiased estimator of sigma cpct = makecdiscr(mu,sigstar,... 'ClassNames',{'setosa','versicolor','virginica'})```
```cpct = CompactClassificationDiscriminant PredictorNames: {'x1' 'x2' 'x3' 'x4'} ResponseName: 'Y' CategoricalPredictors: [] ClassNames: {'setosa' 'versicolor' 'virginica'} ScoreTransform: 'none' DiscrimType: 'linear' Mu: [3x4 double] Coeffs: [3x3 struct] Properties, Methods ```

## Input Arguments

collapse all

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.

Data Types: `single` | `double`

Within-class covariance, specified as a matrix of scalar values.

• For a linear discriminant, `Sigma` is a symmetric, positive semidefinite matrix of size `p`-by-`p`, where `p` is the number of predictors.

• For a quadratic discriminant, `Sigma` is an array of size `p`-by-`p`-by-`K`, where `K` is the number of classes. For each `i`, `Sigma(:,:,i)` is a symmetric, positive semidefinite matrix.

Data Types: `single` | `double`

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

Before R2021a, use commas to separate each name and value, and enclose `Name` in quotes.

Example: `'ClassNames',{'setosa' 'versicolor' 'virginica'}` specifies a discriminant analysis classifier that uses `'setosa'`, `'versicolor'`, and `'virginica'` as the grouping variables.

Class names as ordered in `Mu`, specified as the comma-separated pair consisting of `'ClassNames'` and an array containing grouping variables. Use any data type for a grouping variable, including numeric vector, categorical vector, logical vector, character array, string array, or cell array of character vectors.

The default is `1:K`, where `K` is the number of classes (the number of rows of `Mu`).

Example: `'ClassNames',{'setosa' 'versicolor' 'virginica'}`

Data Types: `single` | `double` | `logical` | `char` | `string` | `cell`

Cost of misclassification, specified as the comma-separated pair consisting of `'Cost'` and a square matrix, where `Cost(i,j)` is the cost of classifying a point into class `j` if its true class is `i`. Alternatively, `Cost` can be a structure `S` having two fields: `S.ClassNames` containing the group names as a variable of the same type as `y`, and `S.ClassificationCosts` containing the cost matrix.

The default is `Cost(i,j)=1` if `i~=j`, and `Cost(i,j)=0` if `i=j`.

Data Types: `single` | `double` | `struct`

Predictor variable names, specified as the comma-separated pair consisting of `'PredictorNames'` and a string array or cell array of character vectors containing the names for the predictor variables, in the order in which they appear in `X`.

Data Types: `string` | `cell`

Prior probabilities for each class, specified as the comma-separated pair consisting of `'Prior'` and one of the following:

• `'uniform'`, meaning all class prior probabilities are equal

• A vector containing one scalar value for each class

• A structure `S` with two fields:

• `S.ClassNames` containing the class names as a variable of the same type as `ClassNames`

• `S.ClassProbs` containing a vector of corresponding probabilities

Data Types: `char` | `string` | `single` | `double` | `struct`

Response variable name, specified as the comma-separated pair consisting of `'ResponseName'` and a character vector or string scalar containing the name of the response variable `y`.

Example: `'ResponseName','Response'`

Data Types: `char` | `string`

## Output Arguments

collapse all

Discriminant analysis classifier, returned as a discriminant analysis classifier object of class `CompactClassificationDiscriminant`. You can use the `predict` method to predict classification labels for new data.

## Tips

• You can change the discriminant type using dot notation after constructing `cobj`:

`cobj.DiscrimType = 'discrimType'`

where `discrimType` is one of `'linear'`, `'quadratic'`, `'diagLinear'`, `'diagQuadratic'`, `'pseudoLinear'`, or `'pseudoQuadratic'`. You can change between linear types or between quadratic types, but cannot change between a linear and a quadratic type.

• `cobj` is a linear classifier when `Sigma` is a matrix. `cobj` is a quadratic classifier when `Sigma` is a three-dimensional array.

## Version History

Introduced in R2014a
{"ft_lang_label":"__label__en","ft_lang_prob":0.54344237,"math_prob":0.8903174,"size":4596,"snap":"2022-40-2023-06","text_gpt3_token_len":1138,"char_repetition_ratio":0.12086237,"word_repetition_ratio":0.04313099,"special_character_ratio":0.23585726,"punctuation_ratio":0.1880559,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99591815,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-02T18:49:33Z\",\"WARC-Record-ID\":\"<urn:uuid:01213fcd-468c-4743-8ac7-58c131d62c17>\",\"Content-Length\":\"101885\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:00e19229-8f0d-44f9-bf10-8760ebbed894>\",\"WARC-Concurrent-To\":\"<urn:uuid:a300c442-e366-4387-aed5-59b3091fa9bf>\",\"WARC-IP-Address\":\"23.34.160.82\",\"WARC-Target-URI\":\"https://www.mathworks.com/help/stats/makecdiscr.html\",\"WARC-Payload-Digest\":\"sha1:DGNKFOWNEWL52ZV23IJTF7VR4NAR264Z\",\"WARC-Block-Digest\":\"sha1:7UGIV7JCTB4HUPVCYFNZT7Z2DLX25W57\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337339.70_warc_CC-MAIN-20221002181356-20221002211356-00636.warc.gz\"}"}