# logp

Log unconditional probability density for discriminant analysis classifier

## Syntax

``lp = logp(mdl,X)``

## Description

example

````lp = logp(mdl,X)` returns the log of the unconditional probability density of each row of the predictor data, computed using the discriminant analysis classifier `mdl`.```

## Examples

collapse all

Construct a discriminant analysis classifier for Fisher's iris data, and examine its prediction for an average measurement.

Load Fisher's iris data and construct a default discriminant analysis classifier.

```load fisheriris Mdl = fitcdiscr(meas,species);```

Find the log probability of the discriminant model applied to an average iris.

`logpAverage = logp(Mdl,mean(meas))`
```logpAverage = -1.7254 ```

## Input Arguments

collapse all

Trained discriminant analysis classifier, specified as a `ClassificationDiscriminant` or `CompactClassificationDiscriminant` model object trained with `fitcdiscr`.

Predictor data to classify, specified as a matrix. Each row of the matrix represents an observation, and each column represents a predictor. The number of columns in `X` must equal the number of predictors in `mdl`.

## Output Arguments

collapse all

Logarithms of unconditional probability densities, specified as a column vector with the same number of rows as `X`. Each entry is the logarithm of the unconditional probability density of the corresponding row of `X`.

collapse all

### Unconditional Probability Density

The unconditional probability density of a point x of a discriminant analysis model is

`$P\left(x\right)=\sum _{k=1}^{K}P\left(k\right)P\left(x|k\right),$`

where P(k) is the prior probability of class k, P(x|k) is the conditional density of x given class k, and K is the total number of classes. The conditional density function of the multivariate normal with 1-by-d mean μk and d-by-d covariance Σk at a 1-by-d point x is

`$P\left(x|k\right)=\frac{1}{{\left({\left(2\pi \right)}^{d}|{\Sigma }_{k}|\right)}^{1/2}}\mathrm{exp}\left(-\frac{1}{2}\left(x-{\mu }_{k}\right){\Sigma }_{k}^{-1}{\left(x-{\mu }_{k}\right)}^{T}\right),$`

where $|{\Sigma }_{k}|$ is the determinant of Σk, and ${\Sigma }_{k}^{-1}$ is the inverse matrix.

## Version History

Introduced in R2011b