Mahalanobis distance ==================== * Article * Talk The **Mahalanobis distance** is a measure of the distance between a point P {\\displaystyle P} !{\displaystyle P} and a probability distribution D {\\displaystyle D} !{\displaystyle D} , introduced by P. C. Mahalanobis in 1936.[\[1\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-1) The mathematical details of Mahalanobis distance first appeared in the _Journal of The Asiatic Society of Bengal_ in 1936.[\[2\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-2) 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).[\[3\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-3) [\[4\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-4) R.C. Bose later obtained the sampling distribution of Mahalanobis distance, under the assumption of equal dispersion.[\[5\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-5) It is a multivariate generalization of the square of the standard score z \= ( x − μ ) / σ {\\displaystyle z=(x-\\mu )/\\sigma } !{\displaystyle z=(x-\mu )/\sigma } : how many standard deviations away P {\\displaystyle P} !{\displaystyle P} is from the mean of D {\\displaystyle D} !{\displaystyle D} . This distance is zero for P {\\displaystyle P} !{\displaystyle P} at the mean of D {\\displaystyle D} !{\displaystyle D} and grows as P {\\displaystyle P} !{\displaystyle P} moves away from the mean along each principal component axis. If each of these axes is re-scaled to have unit variance, 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 ---------- edit Given a probability distribution Q {\\displaystyle Q} on R N {\\displaystyle \\mathbb {R} ^{N}} , with mean μ → \= ( μ 1 , μ 2 , μ 3 , … , μ N ) T {\\displaystyle {\\vec {\\mu }}=(\\mu \_{1},\\mu \_{2},\\mu \_{3},\\dots ,\\mu \_{N})^{\\mathsf {T}}} and positive semi-definite covariance matrix Σ {\\displaystyle \\mathbf {\\Sigma } } , the Mahalanobis distance of a point x → \= ( x 1 , x 2 , x 3 , … , x N ) T {\\displaystyle {\\vec {x}}=(x\_{1},x\_{2},x\_{3},\\dots ,x\_{N})^{\\mathsf {T}}} from Q {\\displaystyle Q} is [\[6\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-6) d M ( x → , Q ) \= ( x → − μ → ) T Σ − 1 ( x → − μ → ) . {\\displaystyle d\_{M}({\\vec {x}},Q)={\\sqrt {({\\vec {x}}-{\\vec {\\mu }})^{\\mathsf {T}}\\mathbf {\\Sigma } ^{-1}({\\vec {x}}-{\\vec {\\mu }})}}.} Given two points x → {\\displaystyle {\\vec {x}}} and y → {\\displaystyle {\\vec {y}}} in R N {\\displaystyle \\mathbb {R} ^{N}} , the Mahalanobis distance between them with respect to Q {\\displaystyle Q} is d M ( x → , y → ; Q ) \= ( x → − y → ) T Σ − 1 ( x → − y → ) . {\\displaystyle d\_{M}({\\vec {x}},{\\vec {y}};Q)={\\sqrt {({\\vec {x}}-{\\vec {y}})^{\\mathsf {T}}\\mathbf {\\Sigma } ^{-1}({\\vec {x}}-{\\vec {y}})}}.} which means that d M ( x → , Q ) \= d M ( x → , μ → ; Q ) {\\displaystyle d\_{M}({\\vec {x}},Q)=d\_{M}({\\vec {x}},{\\vec {\\mu }};Q)} . Since Σ {\\displaystyle \\mathbf {\\Sigma } } is positive semi-definite , so is Σ − 1 {\\displaystyle \\mathbf {\\Sigma } ^{-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.[\[7\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-7) By the spectral theorem , Σ {\\displaystyle \\mathbf {\\Sigma } } can be decomposed as Σ \= S T S {\\displaystyle \\mathbf {\\Sigma } =\\mathbf {S} ^{T}\\mathbf {S} } for some real N × N {\\displaystyle N\\times N} matrix. One choice for S {\\displaystyle \\mathbf {S} } is the symmetric square root of Σ {\\displaystyle \\mathbf {\\Sigma } } , which is the standard deviation matrix .[\[8\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-Das-8) This gives us the equivalent definition d M ( x → , y → ; Q ) \= ‖ S − 1 ( x → − y → ) ‖ {\\displaystyle d\_{M}({\\vec {x}},{\\vec {y}};Q)=\\|\\mathbf {S} ^{-1}({\\vec {x}}-{\\vec {y}})\\|} where ‖ ⋅ ‖ {\\displaystyle \\|\\cdot \\|} is the Euclidean norm. That is, the Mahalanobis distance is the Euclidean distance after a whitening transformation . The existence of S {\\displaystyle \\mathbf {S} } is guaranteed by the spectral theorem, but it is not unique. Different choices have different theoretical and practical advantages.[\[9\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-9) In practice, the distribution Q {\\displaystyle Q} is usually the sample distribution from a set of IID samples from an underlying unknown distribution, so μ {\\displaystyle \\mu } is the sample mean, and Σ {\\displaystyle \\mathbf {\\Sigma } } is the covariance matrix of the samples. When the affine span of the samples is not the entire R N {\\displaystyle \\mathbb {R} ^{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 R N {\\displaystyle \\mathbb {R} ^{N}} , the samples can be first orthogonally projected to R n {\\displaystyle \\mathbb {R} ^{n}} , where n {\\displaystyle n} is the dimension of the affine span of the samples, then the Mahalanobis distance can be computed as usual. Intuitive explanation --------------------- edit This section **does not cite any sources **. Please help improve this section by adding citations to reliable sources . Unsourced material may be challenged and removed . _(May 2021)_ _(Learn how and when to remove this message )_ 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 σ {\\displaystyle {\\frac {\\lVert x-\\mu \\rVert \_{2}}{\\sigma }}} , which reads: testpoint − sample mean standard deviation {\\displaystyle {\\frac {{\\text{testpoint}}-{\\text{sample mean}}}{\\text{standard 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. Applications ------------ edit Mahalanobis distance is widely used in cluster analysis and classification techniques. It is closely related to Hotelling's T-square distribution used for multivariate statistical testing and Fisher's linear discriminant analysis that is used for supervised classification .[\[13\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-13) In order to use the Mahalanobis distance to classify a test point as belonging to one of _N_ classes, one first estimates the covariance matrix of each class, usually based on samples known to belong to each class. Then, given a test sample, one computes the Mahalanobis distance to each class, and classifies the test point as belonging to that class for which the Mahalanobis distance is minimal. Mahalanobis distance and leverage are often used to detect outliers , especially in the development of linear regression models. A point that has a greater Mahalanobis distance from the rest of the sample population of points is said to have higher leverage since it has a greater influence on the slope or coefficients of the regression equation. Mahalanobis distance is also used to determine multivariate outliers. Regression techniques can be used to determine if a specific case within a sample population is an outlier via the combination of two or more variable scores. Even for normal distributions, a point can be a multivariate outlier even if it is not a univariate outlier for any variable (consider a probability density concentrated along the line x 1 \= x 2 {\\displaystyle x\_{1}=x\_{2}} , for example), making Mahalanobis distance a more sensitive measure than checking dimensions individually. Mahalanobis distance has also been used in ecological niche modelling ,[\[14\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-14) [\[15\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-15) as the convex elliptical shape of the distances relates well to the concept of the fundamental niche . Another example of usage is in finance, where Mahalanobis distance has been used to compute an indicator called the "turbulence index",[\[16\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-16) which is a statistical measure of financial markets abnormal behaviour. An implementation as a Web API of this indicator is available online.[\[17\]](https://en.wikipedia.org/wiki/Mahalanobis_distance?utm_source=chatgpt.com#cite_note-17)