ArticleslgStudy

mathematics

Mahalanobis distance

Mahalanobis distance is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Mahalanobis distance rather than just read about it. In short: The Mahalanobis distance is a measure of the distance between a point P and a probability distribution D, introduced by P. C.

Mahalanobis distance — main illustration
Mahalanobis distance — illustration

Key takeaways

  • Mahalanobis distance belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Mahalanobis distance to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Mahalanobis distance from memory before moving on to harder problems.

Reference excerpt

The Mahalanobis distance is a measure of the distance between a point P and a probability distribution D, introduced by P. C. Mahalanobis in 1936. The mathematical details of Mahalanobis distance first appeared in the Journal of The Asiatic Society of Bengal in 1936. Mahalanobis's definition was prompted by the problem of identifying the similarities of skulls based on measurements (the earliest work related to similarities of skulls are from 1922 and another later work is from 1927). R.C. Bose later obtained the sampling distribution of Mahalanobis distance, under the assumption of equal dispersion. It is a multivariate generalization of the absolute value of the standard score z=(x−μ)/σ: how many standard deviations away P is from the mean of D. This distance is zero for P at the mean of D and grows as P moves away from the mean along each principal component axis. If each of these axes is re-scaled to have unit variance, and whitened to be uncorrelated, then the Mahalanobis distance corresponds to standard Euclidean distance in the transformed space. The Mahalanobis distance is thus unitless, scale-invariant, and takes into account the correlations of the data set.

Definition Given a probability distribution Q on ℝN, with mean μ→=(μ1,μ2,μ3,…,μN)𝖳 and positive semi-definite covariance matrix 𝜮, the Mahalanobis distance of a point x→=(x1,x2,x3,…,xN)𝖳 from Q is dM(x→,Q)=(x→−μ→)𝖳𝜮−1(x→−μ→).Given two points x→ and y→ in ℝN, the Mahalanobis distance between them with respect to Q isdM(x→,y→;Q)=(x→−y→)𝖳𝜮−1(x→−y→).which means that dM(x→,Q)=dM(x→,μ→;Q). Since 𝜮 is positive semi-definite, so is 𝜮−1. Thus, the square roots are always defined. We can find useful decompositions of the squared Mahalanobis distance that help to explain some reasons for the outlyingness of multivariate observations and also provide a graphical tool for identifying outliers. By the spectral theorem, 𝜮 can be decomposed as 𝜮=𝐒T𝐒 for some real N×N matrix. One choice for 𝐒 is the symmetric square root of 𝜮, which is the standard deviation matrix. This gives us the equivalent definitiondM(x→,y→;Q)=‖𝐒−1(x→−y→)‖where ‖⋅‖ is the Euclidean norm. That is, the Mahalanobis distance is the Euclidean distance after a whitening transformation. The existence of 𝐒 is guaranteed by the spectral theorem, but it is not unique. Different choices have different theoretical and practical advantages. In practice, the distribution Q is usually the sample distribution from a set of IID samples from an underlying unknown distribution, so μ is the sample mean, and 𝜮 is the covariance matrix of the samples. When the affine span of the samples is not the entire ℝN, the covariance matrix would not be positive-definite, which means the above definition would not work. However, in general, the Mahalanobis distance is preserved under any full-rank affine transformation of the affine span of the samples. So in case the affine span is not the entire ℝN, the samples can be first orthogonally projected to ℝn, where n is the dimension of the affine span of the samples, then the Mahalanobis distance can be computed as usual.

Intuitive explanation Consider the problem of estimating the probability that a test point in N-dimensional Euclidean space belongs to a set, where we are given sample points that definitely belong to that set. Our first step would be to find the centroid or center of mass of the sample points. Intuitively, the closer the point in question is to this center of mass, the more likely it is to belong to the set. However, we also need to know if the set is spread out over a large range or a small range, so that we can decide whether a given distance from the center is noteworthy or not. The simplistic approach is to estimate the standard deviation of the distances of the sample points from the center of mass. If the distance between the test point and the center of mass is less than one standard deviation, then we might conclude that it is highly probable that the test point belongs to the set. The further away it is, the more likely that the test point should not be classified as belonging to the set. This intuitive approach can be made quantitative by defining the normalized distance between the test point and the set to be ‖x−μ‖2σ, which reads: testpoint−sample meanstandard deviation. By plugging this into the normal distribution, we can derive the probability of the test point belonging to the set. The drawback of the above approach was that we assumed that the sample points are distributed about the center of mass in a spherical manner. Were the distribution to be decidedly non-spherical, for instance ellipsoidal, then we would expect the probability of the test point belonging to the set to depend not only on the distance from the center of mass, but also on the direction. In those directions where the ellipsoid has a short axis the test point must be closer, while in those where the axis is long the test point can be further away from the center. Putting this on a mathematical basis, the ellipsoid that best represents the set's probability distribution can be estimated by building the covariance matrix of the samples. The Mahalanobis distance is the distance of the test point from the center of mass divided by the width of the ellipsoid in the direction of the test point.

Normal distributions For a normal distribution in any number of dimensions, the probability density of an observation x→ is uniquely determined by the Mahalanobis distance d:

Pr⁡[x→]dx→=1det⁡(2π𝜮)exp⁡(−(x→−μ→)𝖳𝜮−1(x→−μ→)2)dx→=1det⁡(2π𝜮)exp⁡(−d22)dx→. Specifically, d2 follows the chi-squared distribution with n degrees of freedom, where n is the number of dimensions of the normal distribution. If the number of dimensions is 2, for example, the probability of a particular calculated d being less than some threshold t is 1−e−t2/2. To determine a threshold to achieve a particular probability, p, use t=−2ln⁡(1−p), for 2 dimensions. For number of dimensions other than 2, the cumulative chi-squared distribution should be consulted. In a normal distribution, the region where the Mahalanobis distance is less than one (i.e. the region inside the ellipsoid at distance one) is exactly the region where the probability distribution is concave. The Mahalanobis distance is proportional, for a normal distribution, to the square root of the negative log-likelihood (after adding a constant so the minimum is at zero).

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Mahalanobis distance

Start with the simplest possible case. Write down what Mahalanobis distance claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Mahalanobis distance before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Mahalanobis distance ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Mahalanobis distance

In research
Mahalanobis distance appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Mahalanobis distance in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Mahalanobis distance is common in secondary-school and first-year university syllabi. It links to neighbouring topics Distance, Indian inventions, Multivariate statistics, so understanding it makes those chapters shorter.
In everyday life
Look for Mahalanobis distance outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Mahalanobis distance” →

How to study Mahalanobis distance in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Mahalanobis distance means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Mahalanobis distance out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Mahalanobis distance in simple terms?

The Mahalanobis distance is a measure of the distance between a point P and a probability distribution D, introduced by P. C.

Why does Mahalanobis distance matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Mahalanobis distance?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Mahalanobis distance.

Tags

  • Distance
  • Indian inventions
  • Multivariate statistics
  • Statistical distance

Keep exploring