Methods · Distance
MAHALANOBIS DISTANCE (Mahalanobis Distance)
Mahalanobis distance measures how far apart two points are while taking the relationship (correlation) between criteria into account; the same raw gap can come out small or large depending on whether it fits the criteria's usual pattern of moving together.
Base method's data type: Classical
What Is the Method?
Mahalanobis distance is a distance measure that, in measuring the difference between two numerical vectors, also takes into account how the criteria are related (correlated) to one another. Its input is two vectors of equal length and a covariance matrix summarising the relationship between criteria; its output is a single number. If the criteria are completely independent of one another (if the covariance matrix is the identity matrix), Mahalanobis distance equals Euclidean distance; its real difference appears when the criteria are correlated. It is a building block feeding the "how far is the alternative from the ideal" step in correlation-sensitive versions of ranking methods such as Hellwig.
Prasanta Chandra Mahalanobis introduced it to statistics in 1936, to compare skull measurements across different population groups in India; his question was "how unusual is this group of measurements relative to the usual pattern formed by the other measurements." This question works directly in decision analysis when there is a strong relationship between criteria (such as "large-budget projects generally take longer").
The Philosophy Behind It
Mahalanobis distance is built around one question: does the raw gap between two points fit the criteria's usual pattern of moving together, or does it break that pattern? If two criteria generally rise and fall together (positive correlation), an alternative that deviates in the same direction on both is counted as "usual" and treated as close; an alternative that deviates on only one but not the other is counted as "unusual" and treated as more distant, even when the raw gaps are identical.
This reveals information that Euclidean distance cannot see. Euclidean distance treats every criterion as independent and of equal importance; if two alternatives have the same total deviation, they are equidistant, regardless of whether that deviation fits the criteria's usual relationship. Mahalanobis distance asks exactly this, and can sometimes turn an exact tie under Euclidean distance into a clear difference. If the decision-maker's question is "the criteria are independent, each matters on its own," Euclidean distance suffices; if it is "the criteria are related, and a deviation that runs against this relationship should be treated as riskier," Mahalanobis distance is required.
How It Works
The calculation consists of two steps.
First, establishing the relationship (covariance). The relationship between criteria is summarised in a covariance matrix; this matrix is either computed from existing observations or set from expert judgement (knowledge of which criteria move together). If the criteria are independent of one another, this matrix is the identity matrix (zero off the diagonal), and Mahalanobis distance reduces to Euclidean distance.
Second, the relationship-weighted difference. The raw difference between the two vectors is taken, but this difference is not summed directly; it is weighted by the inverse of the covariance matrix. This weighting shrinks deviations that fit the correlation and inflates deviations that go against it. The square root of the result is the Mahalanobis distance.
If the number of observations is smaller than the number of criteria (for instance, when only two alternatives are being compared), the covariance matrix can be singular (non-invertible); in that case a generalised inverse (Moore-Penrose) is used, and this requires careful interpretation of the results. The formula behind these steps and its implementation in DecisionMind are given on the method page; this card carries no formulas.
How to Read the Output
Mahalanobis distance is a deviation magnitude weighted by correlation; it is not in the same unit as raw Euclidean distance and cannot be compared directly with it. A value of zero means the two vectors are identical. When the covariance matrix is the identity matrix (when the criteria are independent), Mahalanobis and Euclidean distance are numerically equal; this does not mean the two measures say the same thing, but that the relationship happens to be switched off in this particular case.
Mahalanobis distance's most important property is that it can separate two alternatives with the same raw (Euclidean) distance: one that deviates in a way that fits the criteria's usual relationship gets a small Mahalanobis value, while one that deviates in a way that breaks that relationship gets a large one. This distinction depends on the accuracy of the covariance matrix; a wrongly or poorly estimated covariance matrix produces a wrong distinction.
For this reason, instead of writing:
"By Euclidean distance, these two alternatives are equally far from the ideal"
the report should read:
"Although their raw deviations are equal, once the known relationship between the criteria is taken into account, these two alternatives are not equally distant; one fits the usual pattern while the other breaks it"
Data Type and Inputs
Mahalanobis distance works with crisp numerical data. DM3 carries only the base Mahalanobis member under this name; there is no separate extension. You need two numerical vectors of equal length and a covariance matrix showing the relationship between the criteria; this matrix is either computed from a sufficient number of past observations or set from expert judgement. If the number of observations is smaller than the number of criteria, the reliability of the covariance matrix falls and a generalised inverse may be needed; this must be stated in the report. A minimum of two criteria is required; as the number of criteria grows, a reliable covariance matrix requires more observations. Mahalanobis does not produce weights and does not take weights; its input is not criterion weights but the relationship between criteria.
When to Use It, When Not To
Mahalanobis is a suitable choice if there is a known or measurable strong relationship between your criteria (two cost items generally rising together, or a performance measure and a risk measure moving in opposite directions), and you consider this relationship important to the decision. Usability increases when there are enough reliable observations to compute the covariance matrix meaningfully.
It should not be used where the criteria are genuinely independent of one another, or where the relationship cannot be reliably estimated (too few observations, a singular covariance matrix); in that case Euclidean distance is both simpler and more reliable. Where criteria are binary or categorical, Hamming distance should be used rather than Mahalanobis. Where robustness against outliers is the priority, Manhattan distance is more suitable.
A known, strong relationship between criteria that should enter the decision → Mahalanobis
Criteria are independent, or the relationship cannot be reliably estimated → Euclidean
Criteria are binary/categorical → Hamming
Robustness to outliers is the priority → Manhattan
The relationship is disregarded, only a single p setting is wanted → Minkowski
Strengths
Mahalanobis distance's principal strength is that it is the only widely used distance measure that does not disregard the relationship between criteria; none of Euclidean, Manhattan or Minkowski distance does this. It is also naturally insensitive to differences in scale, because the covariance matrix already accounts for each criterion's own variability; it is thereby less dependent on a separate prior normalisation step. On correlated criteria it can reveal a distinction that Euclidean distance conceals (as shown in the Aviation case); this is why it is widely used in statistics for outlier detection (De Maesschalck, Jouan-Rimbaud and Massart, 2000).
Weaknesses
Its limitations depend on the quality of its input, the covariance matrix. First, reliably computing the covariance matrix requires more observations than criteria; with too few observations the matrix is singular (non-invertible) and a generalised inverse must be used, which makes the result harder to interpret. Second, if the covariance matrix has been computed from incorrect or outdated data (if the relationship has changed over time), Mahalanobis distance produces a wrong distinction; the measure is only as good as its input. Third, its calculation and meaning are more abstract than Euclidean or Manhattan distance; explaining the idea of a "correlation-weighted difference" to a decision-maker is harder than explaining "total difference." Fourth, where DM3 compares only two alternatives (as in the J.expected example), a sample covariance cannot be computed; in that case the covariance must be supplied from outside, either from expert judgement or from past data (Roszkowska, 2024).
Common Mistakes
The most common mistake is computing the covariance matrix from a small number of observations and using it without questioning its reliability; a relationship drawn from a handful of observations may not be a genuine pattern. A second mistake is applying Mahalanobis where there is no relationship between the criteria at all (independent criteria) and expecting a result different from Euclidean; for independent criteria the two measures are already equal. A third mistake is computing the covariance matrix once and using it for years without ever updating it; the relationship between criteria can change over time. A fourth mistake is presenting a result from a singular covariance matrix with the same reliability as other analyses, without reporting that a generalised inverse was used.
The governing principle is this:
Mahalanobis distance adds something only when the relationship between criteria is reliably known; if the relationship is unknown or unreliable, Euclidean distance is both simpler and more honest.
Cases
Each case opens with a deviation table, describes in words how the relationship between criteria changes the distance, and shows how to read the result. The first case is DM3's own validation example; the figures were recomputed and verified in Python. The remaining cases are illustrative constructions.
1. Validation: Mahalanobis equals Euclidean for independent criteria (DM3 validation example)
DM3's Mahalanobis distance engine compares two vectors with two criteria (D1-D2): a = (3, 5) and b = (5, 3); the covariance matrix is taken as the identity matrix (Σ=I), that is, the two criteria are treated as independent.
| Vector | D1 | D2 |
|---|---|---|
| a | 3 | 5 |
| b | 5 | 3 |
| Σ (covariance) | [[1,0],[0,1]] |
When the covariance matrix is the identity matrix, the Mahalanobis distance formula reduces to Euclidean distance: the difference vector is (−2, 2), the sum of squares is 8, and its square root is 2.828.
Result: Mahalanobis distance d = 2.828 (= Euclidean distance √8).
This is the method's most basic validation case, in which the independence assumption (Σ=I) is stated explicitly because a reliable covariance cannot be computed from two observations (two points determine a line, and the relationship is undefined).
In the report: "In this case, with the two criteria treated as independent, the Mahalanobis distance is 2.828 and is exactly equal to the Euclidean distance; this is the expected result."
Source: this example is DM3's validation example for the Mahalanobis engine, constructed for illustrative purposes; Mahalanobis's 1936 source concerns skull-measurement comparison and has no connection to this table.
2. Aviation: A difference revealed by correlation in aircraft-parts supplier selection
An aviation firm compares two supplier profiles against two criteria (part-weight deviation, fuel-consumption deviation) by their deviation from the ideal (0,0). According to the firm's historical data, these two criteria are strongly positively correlated (r=0.90): a part whose weight increases nearly always increases fuel consumption as well.
| Profile | Weight deviation | Fuel deviation | Pattern |
|---|---|---|---|
| X | 2.0 | 2.0 | Both increased in the same direction (usual) |
| Y | 2.0 | -2.0 | Weight increased, fuel decreased (unusual) |
Looking at raw Euclidean distance, X and Y are exactly the same distance from the ideal: both give square root(2²+2²)=2.828. No difference between the two profiles is visible.
Once the covariance matrix (r=0.90, taking both criteria's variability as 1) is taken into account, the picture changes entirely: X's deviation fits the criteria's usual pattern of moving together (both increased), so its Mahalanobis distance shrinks; Y's deviation breaks this pattern (one increased, the other decreased, a combination that contradicts the high positive correlation), so its Mahalanobis distance grows.
| Profile | Euclidean distance | Mahalanobis distance |
|---|---|---|
| X | 2.828 | 2.052 |
| Y | 2.828 | 8.944 |
Two profiles that are an exact tie under Euclidean distance come out roughly 4.4 times apart once correlation is taken into account. The firm hesitates here: Y's combination (weight rising while fuel falls) goes against the usual relationship shown by past data; this could stem either from a measurement error or from a genuinely unusual, and separately verifiable, engineering solution. Euclidean distance shows none of this distinction; Mahalanobis distance points to it directly.
In the report: "X and Y are equal in raw deviation magnitude (Euclidean 2.828). However, once the known strong relationship between weight and fuel consumption (r=0.90) is taken into account, Y (Mahalanobis 8.944) is a far more unusual profile than X (Mahalanobis 2.052) and should be separately verified."
3. Telecommunications: The effect of negative correlation in infrastructure-provider selection
A telecommunications firm compares two provider profiles against two criteria (bandwidth-capacity deviation, latency deviation) by their deviation from the ideal (0,0). These two criteria are negatively related (r=-0.80): infrastructure with rising capacity generally reduces latency.
| Profile | Capacity deviation | Latency deviation | Pattern |
|---|---|---|---|
| P | 2.0 | -2.0 | Capacity risen, latency fallen (usual) |
| Q | 2.0 | 2.0 | Capacity risen, latency also risen (unusual) |
By raw Euclidean distance, P and Q are again exactly equal: both give square root(2²+2²)=2.828. Once the covariance matrix (r=-0.80) is taken into account, P's pattern (capacity and latency moving in opposite directions) fits the pattern expected under negative correlation, so its Mahalanobis distance comes out small; Q's pattern (both moving in the same direction) contradicts the negative correlation, so its Mahalanobis distance comes out large.
| Profile | Euclidean distance | Mahalanobis distance |
|---|---|---|
| P | 2.828 | 2.108 |
| Q | 2.828 | 6.325 |
The firm hesitates here: Q's profile (latency also rising as capacity rises) goes against the infrastructure's expected behaviour, and the cause of this inconsistency (a fault, a measurement error, a different architecture) should be separately investigated. While Euclidean distance cannot distinguish these two profiles, Mahalanobis distance shows Q as roughly 3 times more distant than P.
In the report: "P and Q are equal in raw deviation magnitude (Euclidean 2.828). Once the known negative relationship between capacity and latency (r=-0.80) is taken into account, Q (Mahalanobis 6.325) is markedly more unusual than P (Mahalanobis 2.108); this result requires Q's architecture to be separately examined."
4. What Not to Do
In the Aviation case, seeing that X and Y have equal Euclidean distance and reporting "the two profiles are equally risky" without taking correlation into account at all is the first error. A second error, in the Telecommunications case, is deriving the covariance matrix (r=-0.80) from only two observations without verification and presenting it as certain fact; the relationship should come from past data or expert judgement, and this source must be stated in the report. A third error is treating Mahalanobis distance as "more advanced" than Euclidean in every case and applying it to a table where the criteria are genuinely independent; for independent criteria the two measures already give the same result, and the extra complexity brings no benefit.
Sources
For the formula behind these steps and its implementation in DecisionMind, see the method page: decisionmind.app/library/mahalanobis-distance
Mahalanobis, P. C. (1936). On the Generalised Distance in Statistics. Proceedings of the National Institute of Sciences of India, 2(1), 49-55. (no DOI; DOI of the 2018 reprint: 10.1007/s13171-019-00164-5, Sankhya A, 80(S1), 1-7.)
De Maesschalck, R., Jouan-Rimbaud, D., & Massart, D. L. (2000). The Mahalanobis distance. Chemometrics and Intelligent Laboratory Systems, 50(1), 1-18. DOI: 10.1016/s0169-7439(99)00047-7
Roszkowska, E. (2024). Modifying Hellwig's Method for Multi-Criteria Decision-Making with Mahalanobis Distance for Addressing Asymmetrical Relationships. Symmetry, 16(1), 77. DOI: 10.3390/sym16010077
Deza, M. M., & Deza, E. (2009). Encyclopedia of Distances. Springer-Verlag Berlin Heidelberg. DOI: 10.1007/978-3-642-00234-2_1