# 最小二乘法

最小二乘法是一种参数估计原理：选择模型的未知参数，使观测数据与模型预测值之间的偏差平方和最小。在其最常见的形式——线性最小二乘回归——中，美国国家标准与技术研究院（U.S. National Institute of Standards and Technology）称它是使用范围远超其他方法的建模方法，并且它是许多其他技术的基础，包括非线性最小二乘、加权最小二乘和LOESS。<sup>[1](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm)</sup>

| 关键事实 | 详情 |
|---|---|
| 准则 | 最小化 \( Q = \sum_{i=1}^{n} [y_i - f(\vec{x}_i;\hat{\vec{\beta}})]^2 \)，即观测响应与模型之间偏差的平方和。<sup>[2](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)</sup> |
| 首次发表 | 阿德里安-马里·勒让德（Adrien-Marie Legendre），附录《论最小二乘方法》（Sur la méthode des moindres quarrés），载于《确定彗星轨道的新方法》（*Nouvelles méthodes pour la détermination des orbites des comètes*），巴黎（Paris），1805年。<sup>[3](https://stemmascience.org/en/node/least_squares/)</sup> |
| 高斯的说法 | 卡尔·弗里德里希·高斯（Carl Friedrich Gauss）于1809年声称自1795年以来一直使用该方法；他在1809年给出了概率论论证，1823年又给出了不依赖分布的论证。<sup>[3](https://stemmascience.org/en/node/least_squares/)</sup><sup> • </sup><sup>[4](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup> |
| 最优性 | 在误差服从正态分布时，最小二乘估计是最优的（高斯，1798年手稿工作）；1821年高斯证明，无论误差分布如何，在观测的所有无偏线性函数中，最小二乘估计具有最小方差。<sup>[5](https://emtoolbox.nist.gov/publications/NBSIR74-587.pdf)</sup> |
| 著名应用 | 高斯对小行星谷神星（Ceres）的22次观测应用最小二乘法，预测它将在哪里重新出现；弗朗茨·冯·扎克（Franz von Zach）于1801年12月7日观测到了它。<sup>[6](https://www.jpl.nasa.gov/news/ceres-keeping-well-guarded-secrets-for-215-years/)</sup> |
| 计算 | 满秩问题通过QR或LQ分解（LAPACK xGELS）求解；秩亏问题使用奇异值分解（xGELSS、xGELSD）。<sup>[7](https://www.netlib.org/lapack/lug/node27.html)</sup> |
| 主要弱点 | 对离群值的敏感性：一两个异常数据点就可能严重扭曲最小二乘分析。<sup>[1](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm)</sup> |

## 拟合准则

在最小二乘估计中，回归函数 \( f(\vec{x};\vec{\beta}) \) 的未知参数 \( \beta_0, \beta_1, \ldots \) 通过寻找使观测响应与模型函数部分之间偏差平方和最小的数值来估计。参数被视为优化的变量，而预测变量值充当已知系数；估计值写作 \( \hat{\beta}_0, \hat{\beta}_1, \ldots \)，以区别于真值。<sup>[2](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)</sup>

对于直线模型 \( y = \beta_0 + \beta_1 x + \varepsilon \)，对 \( Q \) 关于两个估计值求偏导数，令其为零，并求解所得的两个方程，得到闭式估计量：

\[ \hat{\beta}_1 = \frac{\sum_{i=1}^{n} (x_i-\bar{x})(y_i-\bar{y})}{\sum_{i=1}^{n} (x_i-\bar{x})^2}, \qquad \hat{\beta}_0 = \bar{y} - \hat{\beta}_1\bar{x} \]

这些公式表明，估计量是预测变量和响应变量的函数，并且除非 \( \bar{x} = 0 \)，否则彼此相关；远离真实斜率的斜率估计往往会拖累截距估计，这在计算预测值的不确定性时很重要。<sup>[2](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)</sup>

对于线性模型，最小化通常用微积分解析完成；对于非线性模型，几乎总是必须用迭代数值算法完成，例如高斯-牛顿迭代或其莱文贝格-马夸特变体。<sup>[2](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)</sup><sup> • </sup><sup>[8](https://www.nist.gov/publications/fitting-natures-basic-functions-part-iii-exponentials-sinusoids-and-nonlinear-least)</sup>

## “线性”的含义

在统计意义上，当每个解释变量都乘以一个未知参数时，模型就是线性的，例如 \( f(\vec{x};\vec{\beta}) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \ldots \)。该术语并不要求直线：二次曲线 \( \beta_0 + \beta_1 x + \beta_{11} x^2 \)、关于 \( \ln(x) \) 的直线，或关于 \( \sin(x) \) 的多项式，在参数上都是线性的。相比之下，\( f(x;\vec{\beta}) = \beta_0 + \beta_0\beta_1 x \) 关于 \( x \) 是线性的，但关于参数不是线性的，因为斜率是两个参数的乘积，所以它需要非线性最小二乘。<sup>[1](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm)</sup>

## 历史与优先权之争

**勒让德首先发表。** 该方法出现在勒让德《确定彗星轨道的新方法》附录第72—75页，该书出版于1805年；附录其余部分将该技术应用于测量子午线每度的弧长。<sup>[9](https://www.gtfp.cs.rhul.ac.uk/pulskamp/Legendre/legendre.html)</sup> 高斯在其1809年《天体运动论》（*Theoria motus*）中称最小二乘为“我的原理，自1795年以来我一直使用它”，并承认勒让德首先发表了它；由此产生的优先权之争持续了数十年，芝加哥大学（University of Chicago）统计学史学家斯蒂芬·M·斯蒂格勒（Stephen M. Stigler）分析了高斯1809年的说法，同时指出不能将其视为定论。<sup>[3](https://stemmascience.org/en/node/least_squares/)</sup> 当勒让德于1820年发表对高斯的攻击时，争吵达到高潮。<sup>[10](https://www.sciencedirect.com/science/article/pii/0315086077900325)</sup>

**高斯的两个论证。** 勒让德最初的论证不涉及概率考虑；它被提出作为一种组合观测的便利方法。高斯认识到，如果不了解测量误差的概率分布，就无法定义“最佳”值。在标注为1798年的工作中，他证明了当底层分布为正态时最小二乘值的最优性；1821年，他证明无论底层分布如何，该方法在观测的所有可能无偏线性函数中产生最小方差的参数值，这一结果现在称为高斯-马尔可夫定理。<sup>[5](https://emtoolbox.nist.gov/publications/NBSIR74-587.pdf)</sup> 在1839年2月28日致弗里德里希·贝塞尔（Friedrich Bessel）的信中，高斯写道，他认为最佳线性无偏估计比最大似然更基本，并且更喜欢他1823年的论证而非1809年的分析。<sup>[4](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup>

**谷神星。** 该方法首次重大公开成功出现在轨道确定中。朱塞佩·皮亚齐（Giuseppe Piazzi）于1801年1月1日发现谷神星，在22次观测后它隐没在太阳后方；现有技术假设圆轨道或抛物线轨道，均不合适。时年24岁的高斯开发了一套通用的轨道确定流程，用最小二乘迭代改进它，并生成了与其他天文学家预报明显不同的星历表。弗朗茨·冯·扎克利用高斯的预测于1801年12月7日重新找到谷神星，随后威廉·奥尔伯斯（Wilhelm Olbers）于1802年1月2日也观测到它。<sup>[11](https://www.nasa.gov/wp-content/uploads/2025/07/a-history-of-near-earth-object-research-sp-4235.pdf)</sup><sup> • </sup><sup>[6](https://www.jpl.nasa.gov/news/ceres-keeping-well-guarded-secrets-for-215-years/)</sup> 用于非线性优化的Ceres Solver库即以此事件命名。<sup>[12](https://ceres-solver.readthedocs.io/latest/)</sup>

## 统计性质与假设

对于随机误差服从正态分布的数据，最小二乘和最大似然参数估计量相同，这是两种方法在实践中经常可以互换的原因之一。<sup>[13](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd43.htm)</sup> 拟合质量可以用残差标准差概括，

\[ \hat{\sigma} = \sqrt{\frac{\sum_{i=1}^{n} [y_i - f(\vec{x}_i;\hat{\vec{\beta}})]^2}{n-p}} \]

其中 \( n \) 是观测数，\( p \) 是拟合参数数。<sup>[2](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)</sup>

该方法的优点包括高效利用数据、从相对较小的数据集获得良好结果，以及有充分理解的理论支持易于解释的统计区间，用于预测、校准和优化。其缺点包括线性模型在较大取值范围内能呈现的形状有限、外推可能很差，以及对离群值敏感。<sup>[1](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm)</sup>

## 加权与正则化变体

**加权最小二乘**处理质量不一的数据。当随机误差的标准差在解释变量上不是常数时，准则的每一项获得权重 \( w_i \)，得到 \( Q = \sum_{i=1}^{n} w_i [y_i - f(\vec{x}_i;\hat{\vec{\beta}})]^2 \)。与每个水平上的方差成反比的权重可产生尽可能精确的参数估计。该方法的主要实际缺点是，其理论假设权重完全已知，而这几乎从不成立；从少量重复观测估计出的权重可能严重且不可预测地影响分析。<sup>[14](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd143.htm)</sup>

**正则化最小二乘**对系数增加惩罚。岭回归最小化 \( \min_{w} \|Xw - y\|_2^2 + \alpha\|w\|_2^2 \)，收缩系数并使其对共线性更稳健；Lasso 增加 \( \ell_1 \) 惩罚 \( \alpha\|w\|_1 \)，可以将系数精确设为零，并且是压缩感知的基础。<sup>[15](https://scikit-learn.org/stable/modules/linear_model.html)</sup>

**稳健替代方法**在存在离群值时取代平方准则。当误差分布非正态或离群值影响方程时，稳健回归是普通最小二乘的适当替代；当误差分布比正态分布尾部更重时，OLS估计量可能较差（普林斯顿稳健性研究，1972年）。<sup>[16](https://www.nist.gov/document/ryannotes-1pdf)</sup>

## 计算

以矩阵形式，问题是 \( \min_x \|Ax - b\|_2 \)。当系统超定（方程多于未知数）且 \( A \) 满秩时，LAPACK驱动例程xGELS使用QR或LQ分解求最小二乘解；当系统欠定时，它求最小范数解。当 \( A \) 可能秩亏时，目标是求同时最小化 \( \|x\|_2 \) 和 \( \|b - Ax\|_2 \) 的最小范数最小二乘解，由完全正交分解（xGELSY）或奇异值分解（xGELSS，以及更快的分治xGELSD）计算。<sup>[7](https://www.netlib.org/lapack/lug/node27.html)</sup> SciPy的`lstsq`提供这些驱动例程，默认使用`gelsd`。<sup>[17](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.lstsq.html)</sup> scikit-learn的`LinearRegression`通过 \( X \) 的奇异值分解计算解，当 \( n_{\text{samples}} \geq n_{\text{features}} \) 时，代价为 \( O(n_{\text{samples}} \cdot n_{\text{features}}^2) \)。<sup>[15](https://scikit-learn.org/stable/modules/linear_model.html)</sup>

## 应用

**大地测量学与测量学。** 美国地质调查局（U.S. Geological Survey）称，最小二乘原理作为大地测量学、摄影测量学和测量学中平差程序的基础，已被普遍接受。<sup>[18](https://www.usgs.gov/publications/generalized-adjustment-least-squares-gals)</sup> 在这些领域，回归常被称为“平差”：人们故意采集比确定参数所需更多的测量值，平差既产生更好的参数估计——通常是二维或三维位置——也产生其不确定性的估计。GNSS定位解算说明了超定情形：至少需要四颗卫星来确定位置和钟差，而通常使用超过四颗。<sup>[19](https://www2.imm.dtu.dk/pubdb/edoc/imm2804.pdf)</sup> 美国国家大地测量局（National Geodetic Survey）在LOCUS等服务中对水准数据应用最小二乘平差。<sup>[20](https://ngs.noaa.gov/locus/LOCUS.xhtml)</sup>

**轨道确定。** 加权最小二乘仍然是组合大量观测以计算改进轨道估计的标准方法，以批处理形式最小化加权残差的平方和；卡尔曼滤波是纳入系统和量测噪声统计的序贯替代方法。<sup>[21](https://ntrs.nasa.gov/api/citations/20040084254/downloads/20040084254.pdf?attachment=true)</sup>

## References

1. [NIST/SEMATECH e-Handbook 4.1.4.1, Linear Least Squares Regression](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm)
2. [NIST/SEMATECH e-Handbook 4.4.3.1, Least Squares](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)
3. [The method of least squares, Stemma](https://stemmascience.org/en/node/least_squares/)
4. [Jan R. Magnus, Gauss on least-squares and maximum-likelihood estimation, Archive for History of Exact Sciences (2022)](https://link.springer.com/article/10.1007/s00407-022-00291-w)
5. [NBSIR 74-587, The Use of the Method of Least Squares in Calibration](https://emtoolbox.nist.gov/publications/NBSIR74-587.pdf)
6. [Ceres: Keeping Well-Guarded Secrets for 215 Years, NASA JPL](https://www.jpl.nasa.gov/news/ceres-keeping-well-guarded-secrets-for-215-years/)
7. [LAPACK Users' Guide, Linear Least Squares (LLS) Problems](https://www.netlib.org/lapack/lug/node27.html)
8. [Fitting Nature's Basic Functions Part III: Exponentials, Sinusoids and Nonlinear Least Squares, NIST](https://www.nist.gov/publications/fitting-natures-basic-functions-part-iii-exponentials-sinusoids-and-nonlinear-least)
9. [Legendre, Royal Holloway University of London](https://www.gtfp.cs.rhul.ac.uk/pulskamp/Legendre/legendre.html)
10. [Stephen M. Stigler, An attack on Gauss, published by Legendre in 1820, Historia Mathematica](https://www.sciencedirect.com/science/article/pii/0315086077900325)
11. [A History of Near-Earth Objects Research, NASA SP-4235](https://www.nasa.gov/wp-content/uploads/2025/07/a-history-of-near-earth-object-research-sp-4235.pdf)
12. [Ceres Solver documentation](https://ceres-solver.readthedocs.io/latest/)
13. [NIST/SEMATECH e-Handbook 4.4.3, How are estimates of the unknown parameters obtained?](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd43.htm)
14. [NIST/SEMATECH e-Handbook 4.1.4.3, Weighted Least Squares Regression](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd143.htm)
15. [scikit-learn 1.9.1 documentation, Linear Models](https://scikit-learn.org/stable/modules/linear_model.html)
16. [Modern Regression Analysis lecture notes, NIST](https://www.nist.gov/document/ryannotes-1pdf)
17. [scipy.linalg.lstsq, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.lstsq.html)
18. [Generalized adjustment by least squares (GALS), U.S. Geological Survey](https://www.usgs.gov/publications/generalized-adjustment-least-squares-gals)
19. [Allan Aasbjerg Nielsen, Least Squares Adjustment: Linear and Nonlinear Weighted Regression Analysis, Technical University of Denmark (2013)](https://www2.imm.dtu.dk/pubdb/edoc/imm2804.pdf)
20. [Leveling Online Computations User Service (LOCUS), National Geodetic Survey](https://ngs.noaa.gov/locus/LOCUS.xhtml)
21. [NASA TM-2004-213230, Methods of Orbit Determination](https://ntrs.nasa.gov/api/citations/20040084254/downloads/20040084254.pdf?attachment=true)

---
*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: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Statistical inference, estimation, sampling, and testing › Regression analysis

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/least-squares

English original: https://www.edgepedia.org/least-squares
