Tutorials › Multivariate Statistics (Graduate) › Mahalanobis Geometry Of LDA

Discriminant Analysis Theory · Tutorial 590 of 975

Mahalanobis Geometry Of LDA

Learn how whitening turns the common-covariance LDA rule into a distance comparison, and how to interpret that comparison in the original coordinates.

Intermediate 12 min read

What You'll Learn

  • State the Gaussian common-covariance assumptions that give the LDA classification rule.
  • Construct whitened coordinates and transform class means consistently.
  • Derive the equivalence between LDA scores and squared Mahalanobis distances.
  • Explain why different valid whitening transformations preserve distances.
  • Distinguish nearest-centroid classification from the prior-adjusted LDA rule.
  • Work classification decisions using diagonal and correlated covariance matrices.

Why LDA Has a Distance Geometry

In linear discriminant analysis, each class has its own mean but shares a covariance matrix. The shared covariance determines how differences between observations should be measured: a change along a high-variance direction is less informative than the same-sized change along a low-variance direction. The resulting distance is the Mahalanobis distance. By transforming the coordinates to remove covariance, this distance becomes ordinary Euclidean distance, and the class means become centroids in the transformed space.

The geometric interpretation is exact under the Gaussian model. With equal class priors and equal misclassification costs, LDA assigns an observation to the class whose transformed centroid is nearest. With unequal priors, the same distance comparison is adjusted by a class-specific prior term; the nearest centroid need not win.

Definition: Let \(X\) be a \(p\)-dimensional observation and \(G\) its class label. In the common-covariance Gaussian model, conditional on \(G=k\), \(X\mid G=k\sim N_p(\mu_k,\Sigma)\), where \(\Sigma\) is symmetric positive definite. A whitening matrix is an invertible matrix \(W\) satisfying \(W\Sigma W^T=I_p\). The transformed observation \(Z=WX\) has identity within-class covariance, and class \(k\)'s transformed mean is \(W\mu_k\).

Positive definiteness matters: it ensures that \(\Sigma^{-1}\) exists and that the whitening transformation is invertible. One standard choice is the symmetric inverse square root \(W=\Sigma^{-1/2}\). Other valid choices can rotate or reflect the whitened coordinates, but they preserve the distances that determine classification.

From Gaussian Scores to Mahalanobis Distance

Suppose class \(k\) has prior probability \(\pi_k>0\), with \(\sum_k\pi_k=1\), and classification uses equal misclassification costs. The Bayes rule assigns \(x\) to a class maximizing \(\pi_k f_k(x)\). In the common-covariance Gaussian model, terms shared by all classes can be removed from the log of this quantity. The resulting LDA score is

$$ \delta_k(x) = x^T\Sigma^{-1}\mu_k -\frac{1}{2}\mu_k^T\Sigma^{-1}\mu_k +\log\pi_k. $$

The same score can be written using the squared Mahalanobis distance from \(x\) to the class mean, \(d_\Sigma^2(x,\mu_k)=(x-\mu_k)^T\Sigma^{-1}(x-\mu_k)\).

Theorem: Under the common-covariance Gaussian model, maximizing the LDA score \(\delta_k(x)\) is equivalent to minimizing \(\frac{1}{2}d_\Sigma^2(x,\mu_k)-\log\pi_k\). If all class priors are equal, this reduces to minimizing \(d_\Sigma^2(x,\mu_k)\).

Proof. Expand the squared distance:

$$ -\frac{1}{2}d_\Sigma^2(x,\mu_k)+\log\pi_k = -\frac{1}{2}x^T\Sigma^{-1}x +x^T\Sigma^{-1}\mu_k -\frac{1}{2}\mu_k^T\Sigma^{-1}\mu_k +\log\pi_k. $$

The first term, \(-\frac{1}{2}x^T\Sigma^{-1}x\), does not depend on \(k\). The remaining terms are exactly \(\delta_k(x)\). Therefore maximizing \(\delta_k(x)\) is equivalent to maximizing \(-\frac{1}{2}d_\Sigma^2(x,\mu_k)+\log\pi_k\), or, after multiplying by \(-1\), minimizing \(\frac{1}{2}d_\Sigma^2(x,\mu_k)-\log\pi_k\). When priors are equal, the prior term is also constant across classes, leaving only the distance comparison. \(\square\)

This theorem separates two ideas that are sometimes conflated. The shared covariance defines the distance scale; the priors can shift the decision in favor of a class even when it is farther away. Thus “nearest centroid” is the exact rule for equal priors, not a description of every prior-adjusted LDA decision.

Whitening Turns the Distance Into Euclidean Length

Let \(W\) be any whitening matrix. Since \(W\Sigma W^T=I_p\), its inverse satisfies \(W^TW=\Sigma^{-1}\). For the transformed observation \(z=Wx\) and transformed class centroid \(m_k=W\mu_k\), it follows that

$$ \|z-m_k\|^2 =(x-\mu_k)^TW^TW(x-\mu_k) =(x-\mu_k)^T\Sigma^{-1}(x-\mu_k) =d_\Sigma^2(x,\mu_k). $$

Consequently, under equal priors, LDA in the original coordinates and nearest-centroid classification in whitened coordinates make the same choice. The word “centroid” here means the transformed class mean \(W\mu_k\); whitening transforms the observation and every class mean using the same matrix.

Theorem: If \(W_1\) and \(W_2\) are two invertible whitening matrices for the same positive-definite \(\Sigma\), then \(W_2=QW_1\) for an orthogonal matrix \(Q\). Thus the two whitened coordinate systems differ only by a rotation or reflection, and all Euclidean distances between transformed observations and centroids agree.

Proof. Define \(Q=W_2W_1^{-1}\). From \(W_1\Sigma W_1^T=I_p\), we have \(\Sigma=W_1^{-1}W_1^{-T}\). Therefore

$$ QQ^T = W_2W_1^{-1}W_1^{-T}W_2^T = W_2\Sigma W_2^T = I_p. $$

Because \(Q\) is square, \(QQ^T=I_p\) implies that \(Q\) is orthogonal. Also \(W_2=QW_1\) by definition. Orthogonal transformations preserve Euclidean length: for any vector \(v\), \(\|Qv\|^2=v^TQ^TQv=v^Tv=\|v\|^2\). Applying this to each difference between a transformed observation and a transformed centroid proves the distance claim. \(\square\)

In the original coordinates, equal Mahalanobis distances form covariance-shaped contours: the sets \(x\) satisfying \((x-\mu)^T\Sigma^{-1}(x-\mu)=c\), for \(c>0\), are ellipsoids centered at \(\mu\). Whitening maps these ellipsoids to Euclidean spheres. This explains why the covariance changes the geometry of “near” without changing the underlying classification rule.

Worked Classification Examples

Worked Example: Diagonal Covariance

Let the two class means be \(\mu_1=(0,0)^T\) and \(\mu_2=(2,0)^T\), with common covariance \(\Sigma=\begin{pmatrix}4&0\\0&1\end{pmatrix}\). Assume equal priors, and classify \(x=(1.2,0.5)^T\).

A whitening matrix is \(W=\begin{pmatrix}1/2&0\\0&1\end{pmatrix}\), because \(W\Sigma W^T=I_2\). The transformed observation and centroids are \(z=(0.6,0.5)^T\), \(m_1=(0,0)^T\), and \(m_2=(1,0)^T\).

The squared Euclidean distances in whitened coordinates are \(\|z-m_1\|^2=0.6^2+0.5^2=0.36+0.25=0.61\) and \(\|z-m_2\|^2=(-0.4)^2+0.5^2=0.16+0.25=0.41\). Thus \(x\) is assigned to class 2.

Checking directly, \(\Sigma^{-1}=\operatorname{diag}(1/4,1)\). The original-coordinate squared distances are \(d_\Sigma^2(x,\mu_1)=1.2^2/4+0.5^2=0.36+0.25=0.61\) and \(d_\Sigma^2(x,\mu_2)=(-0.8)^2/4+0.5^2=0.16+0.25=0.41\). The two calculations agree. A one-unit change in the first coordinate contributes only \(1/4\) to squared distance because that coordinate has variance 4.

Worked Example: A Correlated Covariance

Let \(\Sigma=\begin{pmatrix}4&2\\2&3\end{pmatrix}\), \(\mu_1=(1,0)^T\), and \(\mu_2=(4,2)^T\), again with equal priors. Classify \(x=(3,2)^T\). First note that \(\det(\Sigma)=4\cdot3-2\cdot2=8>0\), and its upper-left entry is positive, so \(\Sigma\) is positive definite.

A factorization is \(\Sigma=LL^T\), where \(L=\begin{pmatrix}2&0\\1&\sqrt{2}\end{pmatrix}\). Hence a whitening matrix is \(W=L^{-1}=\begin{pmatrix}1/2&0\\-1/(2\sqrt{2})&1/\sqrt{2}\end{pmatrix}\). Multiplication gives \(W\Sigma W^T=I_2\).

The transformed observation and centroids are \(Wx=(3/2,1/(2\sqrt{2}))^T\), \(W\mu_1=(1/2,-1/(2\sqrt{2}))^T\), and \(W\mu_2=(2,0)^T\). Therefore \(\|Wx-W\mu_1\|^2=1^2+(1/\sqrt{2})^2=3/2\), while \(\|Wx-W\mu_2\|^2=(-1/2)^2+(1/(2\sqrt{2}))^2=1/4+1/8=3/8\). The nearest transformed centroid is class 2.

For a direct check, \(\Sigma^{-1}=\frac{1}{8}\begin{pmatrix}3&-2\\-2&4\end{pmatrix}\). For class 1, \(x-\mu_1=(2,2)^T\), so \(d_\Sigma^2(x,\mu_1)=\frac{1}{8}(12-8-8+16)=12/8=3/2\). For class 2, \(x-\mu_2=(-1,0)^T\), so \(d_\Sigma^2(x,\mu_2)=3/8\). The nonzero covariance changes the way coordinate differences combine, but whitening makes the same comparison an ordinary Euclidean one.

Worked Example: How Unequal Priors Change the Choice

Consider one-dimensional classes with means \(\mu_1=0\) and \(\mu_2=2\), common variance \(\Sigma=1\), and priors \(\pi_1=0.9\) and \(\pi_2=0.1\). Classify \(x=1.5\). The squared Mahalanobis distances are \(d_\Sigma^2(x,\mu_1)=(1.5-0)^2=2.25\) and \(d_\Sigma^2(x,\mu_2)=(1.5-2)^2=0.25\).

Class 2 is the closer centroid. But the prior-adjusted quantities to minimize are \(\frac12d_\Sigma^2(x,\mu_k)-\log\pi_k\). For class 1 this is \(1.125-\log(0.9)\approx1.125+0.1054=1.2304\). For class 2 it is \(0.125-\log(0.1)\approx0.125+2.3026=2.4276\). The smaller value belongs to class 1, so the LDA rule assigns \(x\) to class 1 despite its greater distance.

This is not a contradiction: the class 1 prior is nine times the class 2 prior, and the decision rule includes that prior information. Whitening still converts the distance terms to Euclidean distances, but it does not remove the prior adjustment.

Interpreting the Geometry and Avoiding a Common Error

A Mahalanobis distance is a Euclidean distance after rescaling and mixing coordinates according to the covariance. If two coordinates are correlated, moving in the direction of their shared variation can be less unusual than moving by the same raw amount in a direction that departs from that pattern. Whitening accounts for this dependence rather than treating each coordinate as an independent scale adjustment.

For two class centroids with equal priors, the points equidistant from them in whitened coordinates satisfy \(\|z-m_1\|^2=\|z-m_2\|^2\). Expanding both squares cancels \(z^Tz\), leaving an equation linear in \(z\). The same equal-distance condition in the original coordinates is \(d_\Sigma^2(x,\mu_1)=d_\Sigma^2(x,\mu_2)\). This pairwise comparison is one way to see why the shared covariance is compatible with linear LDA scores.

Common pitfall: “LDA always assigns an observation to the closest class mean in Mahalanobis distance.” This omits the prior term. The correction is that nearest Mahalanobis centroid is the rule when priors are equal; with unequal priors, minimize \(\frac12d_\Sigma^2(x,\mu_k)-\log\pi_k\). Also, ordinary Euclidean distance in the untransformed coordinates is generally not the relevant distance unless the covariance is proportional to the identity.

The geometric view is useful for diagnosis as well as calculation. It indicates which directions contribute strongly to separation, clarifies why covariance pooling matters, and provides a transparent way to check a computed LDA decision. In practice, fitted class means, covariance matrices, and priors replace their population counterparts; the same formulas apply when the estimated common covariance is positive definite. If it is singular, the inverse-based distances and whitening transformation used here are not defined without additional methods or assumptions.

Check Your Understanding

Use the definitions and results above to answer these questions.

  1. Why does whitening require a positive-definite common covariance matrix in the formulation used here?
  2. State the relationship between squared Euclidean distance after whitening and squared Mahalanobis distance before whitening.
  3. Under what condition does the LDA decision reduce exactly to choosing the nearest Mahalanobis centroid?
  4. What property relates any two valid whitening matrices for the same covariance, and why does it preserve distances?
  5. In the unequal-prior example, which term overturns the nearest-centroid choice?
Clinical Biostats