# 马哈拉诺比斯距离

马哈拉诺比斯距离是一种度量点与分布之间、或两点之间距离的方法，它考虑了变量之间的相关性，并且与测量尺度无关。对于点 \( \mathbf{X} \) 和均值向量 \( \boldsymbol{\mu} \)（其协方差矩阵为 \( \boldsymbol{\Sigma} \)），它定义为

\[ d_{\mathrm{M}}^{2}(\mathbf{X}, \boldsymbol{\mu}) = (\mathbf{X} - \boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} (\mathbf{X} - \boldsymbol{\mu}). \]

它由印度统计学家 P. C. 马哈拉诺比斯（P. C. Mahalanobis）于1936年在论文《论统计学中的广义距离》中提出，该文发表于《印度国家科学研究所学报》第2卷，第49–55页<sup>[1](https://cir.nii.ac.jp/crid/1370017279880961561)</sup><sup> • </sup><sup>[2](https://doi.org/10.1007/978-0-387-32833-1_240)</sup>。更早的一篇1930年论文《论组间差异的检验与度量》包含了关于度量组间差异的相关工作<sup>[3](https://encyclopediaofmath.org/wiki/Mahalanobis_distance)</sup>。

| 关键事实 | 详情 |
|---|---|
| 定义 | \( d_{\mathrm{M}}^{2} = (\mathbf{X} - \boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} (\mathbf{X} - \boldsymbol{\mu}) \)，建立在方差—协方差矩阵之上<sup>[2](https://doi.org/10.1007/978-0-387-32833-1_240)</sup> |
| 起源 | P. C. 马哈拉诺比斯，《论统计学中的广义距离》，《印度国家科学研究所学报》2，49–55（1936）<sup>[1](https://cir.nii.ac.jp/crid/1370017279880961561)</sup> |
| 分布 | 若 \( \mathbf{X} \sim N(\boldsymbol{\mu}, \boldsymbol{\Sigma}) \) 且 \( \boldsymbol{\Sigma} \) 正定，则平方距离服从自由度为 \( p \) 的 \( \chi^{2} \) 分布<sup>[4](https://web.stanford.edu/class/stats305c/lectures/Normal_Theory.html)</sup> |
| 白化视角 | 该距离等于经过使协方差变为单位矩阵的线性变换后，间隔的普通欧几里得范数<sup>[5](https://choxos.github.io/Mathematics-of-ITC/chapters/part6/27-distance-matching.html)</sup> |
| 特例 | 当协方差矩阵为单位矩阵时，马哈拉诺比斯距离退化为欧几里得距离<sup>[6](https://ocw.mit.edu/courses/15-062-data-mining-spring-2003/14e01469b2e5b05ea03c0ca8272a80b7_linalg.pdf)</sup> |
| 主要用途 | 多变量异常值检测、聚类与分类，以及观察性研究中的协变量匹配<sup>[7](https://www.sciencedirect.com/science/article/pii/S0169743999000477)</sup><sup> • </sup><sup>[8](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-031219-041058)</sup> |

## 协方差矩阵的作用

该度量的决定性特征是逆协方差矩阵 \( \boldsymbol{\Sigma}^{-1} \)，有时称为精度矩阵。在原始变量空间中，马哈拉诺比斯距离考虑了相关性，因为它是用所关注数据集的方差—协方差矩阵的逆来计算的<sup>[7](https://www.sciencedirect.com/science/article/pii/S0169743999000477)</sup>。从几何上看，逆协方差沿高方差方向拉伸空间，并压缩低方差方向：在欧几里得意义下接近但位于高方差轴上的点被视为邻近，而沿低方差轴的点则被视为相距较远<sup>[9](https://sites.pitt.edu/~kpele/INFSCI2595_W5_StudyGuide.html)</sup>。

这种行为有一个简洁的代数描述。若 \( \boldsymbol{\Sigma} \succ 0 \)，且 \( B \) 是任意可逆矩阵并满足 \( \boldsymbol{\Sigma} = BB^{T} \)，例如乔列斯基（Cholesky）因子或对称平方根，则两点之间的马哈拉诺比斯距离就是“白化”间隔 \( B^{-1}\boldsymbol{\delta} \) 的欧几里得范数，该变换使协方差变为单位矩阵<sup>[5](https://choxos.github.io/Mathematics-of-ITC/chapters/part6/27-distance-matching.html)</sup>。当变量相互独立时，协方差矩阵为对角矩阵，平方距离与标准化变量的平方和成正比<sup>[10](https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc341.htm)</sup>。

## 与高斯分布和霍特林T²的关系

该距离天然属于多变量正态模型。\( p \) 元正态分布的密度仅通过平方马哈拉诺比斯距离依赖于 \( \mathbf{x} \)，因此所有具有相同平方距离的点具有相同密度；水平集是以均值为中心的椭球<sup>[11](https://online.stat.psu.edu/stat505/Lesson04)</sup>。若 \( \boldsymbol{\Sigma} \) 正定，则 \( (\mathbf{X} - \boldsymbol{\mu})^{T} \boldsymbol{\Sigma}^{-1} (\mathbf{X} - \boldsymbol{\mu}) \sim \chi^{2}_{p} \)；若 \( \boldsymbol{\Sigma} \) 退化，则用穆尔-彭罗斯（Moore–Penrose）逆构成的二次型服从 \( \chi^{2} \) 分布，其自由度等于 \( \boldsymbol{\Sigma} \) 的秩<sup>[4](https://web.stanford.edu/class/stats305c/lectures/Normal_Theory.html)</sup>。

密切相关的霍特林 \( T^{2} \) 统计量由哈罗德·霍特林（Harold Hotelling）于1947年提出，它是一个常数乘以该二次型，可视为学生t统计量的多变量对应物；\( T^{2} \) 控制图是多变量控制图中最流行的一种<sup>[10](https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc341.htm)</sup>。

## 异常值检测

最常见的应用是多变量异常值检测。与数据中心点的平方马哈拉诺比斯距离较大的观测值可能是异常值；当底层分布为多变量正态时，通常使用自由度为 \( p \) 的卡方分布的0.975分位数作为截断值<sup>[12](https://doi.org/10.1016%2Fj.ecosta.2023.04.003)</sup>。该方法被描述为无参数、计算高效，能够考虑变量维度之间的共线性，同时与尺度无关<sup>[13](https://pmc.ncbi.nlm.nih.gov/articles/PMC6450376/)</sup>。

经典形式有一个众所周知的弱点：样本均值和协方差矩阵本身对异常值敏感，因此单个极端观测值就可能扭曲用于标记它的那些量<sup>[14](https://www.sciencedirect.com/science/article/abs/pii/S0022103117302123)</sup>。稳健变体用稳健估计替代均值和协方差，其中最著名的是 P. J. 鲁索（P. J. Rousseeuw）提出的最小协方差行列式（MCD），它找到一个“良好”观测值的子集并计算其协方差；在MCD拟合之后，可以在重加权步骤中根据观测值的马哈拉诺比斯距离对其进行加权<sup>[15](https://scikit-learn.org/stable/modules/covariance.html)</sup>。由相合的高崩溃点稳健估计量构造的马哈拉诺比斯型距离具有渐近卡方分布，但即使样本相当大，对观测值到MCD中心的距离作卡方近似，效果也很差；哈丁（Hardin）和罗克（Rocke）提供了一种改进的F近似，可在各种样本量下给出准确的异常值拒绝点<sup>[16](https://scholarship.claremont.edu/pomona_fac_pub/290/)</sup>。

应用生态学还提出了进一步警告：用于生态位建模的马哈拉诺比斯距离技术的最初描述在如何使用卡方分布将距离转换为概率方面存在错误，这一错误在文献中重复出现，并存在于流行的建模软件中<sup>[13](https://pmc.ncbi.nlm.nih.gov/articles/PMC6450376/)</sup>。

## 实际限制

计算该距离需要可逆的协方差矩阵，而在两种常见情况下这无法满足<sup>[7](https://www.sciencedirect.com/science/article/pii/S0169743999000477)</sup>：

- 当数据在大量变量上测量时，例如近红外光谱，冗余或相关信息会产生多重共线性，导致协方差矩阵奇异或接近奇异而无法求逆。
- 数据集中的对象数量必须大于变量数量。

由于这些原因，通常需要进行特征降维，要么选择少量有意义的变量，要么在来自PCA的主成分而非原始变量上计算距离<sup>[7](https://www.sciencedirect.com/science/article/pii/S0169743999000477)</sup>。当经验协方差因数值原因无法求逆时，可使用收缩估计量，例如莱杜瓦-沃尔夫（Ledoit–Wolf）收缩，它将样本协方差与缩放的单位矩阵凸组合，以获得良态矩阵<sup>[15](https://scikit-learn.org/stable/modules/covariance.html)</sup>。

## 分类、匹配与异常检测

在模式识别中，该距离贯穿于标准工具包：在聚类技术中，如k近邻方法；在判别技术中，如线性、二次和正则化判别分析；在类别建模技术中，如UNEQ、EQ以及SIMCA的修改版<sup>[7](https://www.sciencedirect.com/science/article/pii/S0169743999000477)</sup>。它广泛用于聚类分析以及其他一般分类方法<sup>[2](https://doi.org/10.1007/978-0-387-32833-1_240)</sup>。

在观察性研究中，马哈拉诺比斯距离匹配是与倾向评分并列的标准协变量平衡工具<sup>[8](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-031219-041058)</sup>。直接用马哈拉诺比斯距离对协变量进行匹配，可以更好地平衡协变量的联合分布，且不需要暴露模型，但由于维数灾难，在协变量很多时可能表现不佳；将倾向评分与马哈拉诺比斯距离限制相结合，通常比单独使用任一方法表现更好<sup>[17](https://pmc.ncbi.nlm.nih.gov/articles/PMC9005055/)</sup>。

在深度学习中，一种基于马哈拉诺比斯距离的预训练神经分类器置信分数，假设类条件高斯特征具有共享协方差，在分布外检测和对抗样本检测上取得了最先进的性能。东京大学的龟井亮（Ryo Kamoi）和庆应义塾大学的小林庆（Kei Kobayashi）的分析表明，其有效性源于中间特征中对分类无用的信息，并且将该分数与ODIN检测器结合可提高性能和稳健性<sup>[18](https://arxiv.org/abs/2003.00402)</sup>。

## 硬件实现

由于该距离需要矩阵求逆和二次型，传统的基于CMOS（互补金属氧化物半导体）的实现对于边缘设备而言既笨重又高能耗。2024年《IEEE电子器件学会杂志》（IEEE Journal of the Electron Devices Society）的一篇论文提出了首个铁电FinFET（鳍式场效应晶体管）交叉阵列实现，使用两个交叉阵列和一个基于反相器的阈值电路来检测威斯康星（Wisconsin）乳腺癌数据集中的异常值；它达到了94.1%的准确率，与软件实现相当，同时仅消耗27.2 pJ，目标是在无线传感器节点等人工智能物联网（AIoT）基础设备上实现原位异常值检测<sup>[19](https://ieeexplore.ieee.org/document/10563982/)</sup>。

## References

1. [Mahalanobis, P. C. (1936). On the generalized distance in statistics. Proc. Natl. Inst. Sci. India 2, 49–55. CiNii Research record.](https://cir.nii.ac.jp/crid/1370017279880961561)
2. [Mahalanobis Distance. The Concise Encyclopedia of Statistics, Springer (2008).](https://doi.org/10.1007/978-0-387-32833-1_240)
3. [Mahalanobis distance. Encyclopedia of Mathematics.](https://encyclopediaofmath.org/wiki/Mahalanobis_distance)
4. [Normal Theory, STATS305C lecture notes, Stanford University.](https://web.stanford.edu/class/stats305c/lectures/Normal_Theory.html)
5. [Aggregate-Level Covariate-Distance Matching, The Mathematics of Indirect Treatment Comparisons.](https://choxos.github.io/Mathematics-of-ITC/chapters/part6/27-distance-matching.html)
6. [Linear algebra notes, 15.062 Data Mining, MIT OpenCourseWare.](https://ocw.mit.edu/courses/15-062-data-mining-spring-2003/14e01469b2e5b05ea03c0ca8272a80b7_linalg.pdf)
7. [The Mahalanobis distance. Chemometrics and Intelligent Laboratory Systems (ScienceDirect).](https://www.sciencedirect.com/science/article/pii/S0169743999000477)
8. [Modern Algorithms for Matching in Observational Studies. Annual Review of Statistics and Its Application.](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-031219-041058)
9. [INFSCI 2595 Week 5 Study Guide, University of Pittsburgh.](https://sites.pitt.edu/~kpele/INFSCI2595_W5_StudyGuide.html)
10. [6.3.4.1. Hotelling Control Charts. NIST/SEMATECH e-Handbook of Statistical Methods.](https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc341.htm)
11. [4. Multivariate Normal Distribution, STAT 505, Penn State University.](https://online.stat.psu.edu/stat505/Lesson04)
12. [Multivariate outlier explanations using Shapley values and Mahalanobis distances. Econometrics and Statistics (ScienceDirect).](https://doi.org/10.1016%2Fj.ecosta.2023.04.003)
13. [Etherington, T. R. (2019). Mahalanobis distances and ecological niche modelling: correcting a chi-squared probability error. PeerJ 7:e6678.](https://pmc.ncbi.nlm.nih.gov/articles/PMC6450376/)
14. [Detecting multivariate outliers: Use a robust variant of the Mahalanobis distance (ScienceDirect).](https://www.sciencedirect.com/science/article/abs/pii/S0022103117302123)
15. [2.6. Covariance estimation, scikit-learn user guide.](https://scikit-learn.org/stable/modules/covariance.html)
16. [Hardin, J. S., Rocke, D. M. (2005). The Distribution of Robust Distances. Journal of Computational and Graphical Statistics 14, 928–946.](https://scholarship.claremont.edu/pomona_fac_pub/290/)
17. [Matching Methods for Confounder Control: An Addition to the Epidemiologist's Toolbox (PMC).](https://pmc.ncbi.nlm.nih.gov/articles/PMC9005055/)
18. [Kamoi, R., Kobayashi, K. (2020). Why is the Mahalanobis Distance Effective for Anomaly Detection? arXiv:2003.00402.](https://arxiv.org/abs/2003.00402)
19. [Efficient Implementation of Mahalanobis Distance on Ferroelectric FinFET Crossbar for Outlier Detection. IEEE Journal of the Electron Devices Society (2024).](https://ieeexplore.ieee.org/document/10563982/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Multivariate association and dimension reduction › Titles A to Me

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/mahalanobis-distance

English original: https://www.edgepedia.org/mahalanobis-distance
