# 线性最小二乘

线性最小二乘问题，是指通过最小化观测数据与模型预测值之间偏差的平方和，来求取一个对参数呈线性的模型的参数值。给定观测值 \( y_i \) 和模型 \( f(\vec{x};\vec{\beta}) \)——其中每个解释变量都乘以一个未知参数——估计值 \( \hat{\beta}_0, \hat{\beta}_1, \ldots \) 即是使下式最小化的取值

\[ Q = \sum_{i=1}^{n} \left[ y_i - f(\vec{x}_i;\hat{\vec{\beta}}) \right]^2. \]

写成矩阵形式，设 \( A \) 为 \( m \times n \) 矩阵、\( b \) 为右端项，问题即为 \( \min_{\mathbf{x}} \| A\mathbf{x} - \mathbf{b} \|_2^2 \)，通常针对方程数多于未知数的超定方程组。<sup>[1](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm?pageid=293&pg=page&s=1406)</sup><sup> • </sup><sup>[2](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 准则 | 最小化残差平方和 \( Q = \sum_{i=1}^{n} [y_i - f(\vec{x}_i;\hat{\vec{\beta}})]^2 \)<sup>[1](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm?pageid=293&pg=page&s=1406)</sup> |
| 首次发表 | 勒让德《确定彗星轨道的新方法》（巴黎，1805年）附录“论最小平方法”<sup>[3](https://en.wikisource.org/wiki/A_Source_Book_in_Mathematics/Legendre_on_Least_Squares)</sup> |
| 优先权主张 | 高斯在《天体运动论》（1809年）中称自己自1795年起便使用该原理，但最早由勒让德发表<sup>[3](https://en.wikisource.org/wiki/A_Source_Book_in_Mathematics/Legendre_on_Least_Squares)</sup> |
| 正规方程 | \( A^{\top}A\mathbf{x} = A^{\top}\mathbf{b} \)；求解它们会使条件数平方，即 \( \mathrm{cond}(A^{\top}A) = [\mathrm{cond}(A)]^2 \)<sup>[2](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)</sup> |
| 稳定解法 | 豪斯霍尔德QR分解与奇异值分解（SVD）发展于20世纪60年代和70年代初，至今仍是基本工具<sup>[4](https://www.cambridge.org/core/journals/acta-numerica/article/abs/calculation-of-linear-least-squares-problems/BA6F7F3457DA9172A313452C85E4702E)</sup> |
| 拟合质量 | 残差标准差估计为 \( \hat{\sigma} = \sqrt{Q/(n-p)} \)，其中 \( n \) 为观测数、\( p \) 为参数个数<sup>[1](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm?pageid=293&pg=page&s=1406)</sup> |
| 实际地位 | 美国国家标准与技术研究院（NIST）称线性最小二乘回归为使用最广泛的建模方法<sup>[5](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm?trk=article-ssr-frontend-pulse_little-text-block)</sup> |

## 起源与优先权之争

该方法的首次公开发表出现于1805年，作为阿德里安-马里·勒让德（Adrien-Marie Legendre，1752—1833）《确定彗星轨道的新方法》一书的附录，由菲尔曼·迪多（Firmin Didot）在巴黎印行。勒让德曾在巴黎军事学校教授数学五年，他围绕用彗星观测数据拟合轨道来构建该方法；在附录中，他为每个未知量导出一个“极小方程”，并指出当方程数超过未知数时，不可能将所有误差消去，于是转而最小化其平方和。<sup>[3](https://en.wikisource.org/wiki/A_Source_Book_in_Mathematics/Legendre_on_Least_Squares)</sup><sup> • </sup><sup>[6](https://books.google.fr/books?hl=fr&id=PRcOAAAAQAAJ)</sup>

卡尔·弗里德里希·高斯（Carl Friedrich Gauss）在《天体运动论》（1809年）中称，他自1795年起便使用该原理，但最早由勒让德发表。历史学家斯蒂芬·M. 斯蒂格勒（Stephen M. Stigler）审查证据后倾向于认为高斯先于勒让德掌握该方法，同时表示这不能视为定论；他记录了优先权问题如何在1820年勒让德发表对高斯的攻击时达到高潮。<sup>[3](https://en.wikisource.org/wiki/A_Source_Book_in_Mathematics/Legendre_on_Least_Squares)</sup><sup> • </sup><sup>[7](https://stemmascience.org/en/node/least_squares/)</sup><sup> • </sup><sup>[8](https://www.sciencedirect.com/science/article/pii/0315086077900325)</sup> 美国数学家罗伯特·阿德里安（Robert Adrain）也独立发展出该方法；克利夫兰·阿贝（Cleveland Abbe）于1871年在《美国科学与艺术杂志》上报告了阿德里安的证明。<sup>[9](https://www.gtfp.cs.rhul.ac.uk/pulskamp/Least_Squares/index.html)</sup>

该方法早期的影响主要体现在天文学领域：19世纪初数学天文学的重大进展部分归功于最小二乘，而该方法也成为观测误差演算的基础，被用于社会、经济、生物与心理学问题的研究。<sup>[3](https://en.wikisource.org/wiki/A_Source_Book_in_Mathematics/Legendre_on_Least_Squares)</sup>

## 几何与正规方程

令残差平方函数的梯度为零，即得正规方程

\[ A^{\top}A\,\mathbf{x} = A^{\top}\mathbf{b}. \]

从几何上看，向量 \( A\mathbf{x} \) 是 \( A \) 的列空间中距离 \( \mathbf{b} \) 最近的点，这发生在残差 \( \mathbf{b} - A\mathbf{x} \) 垂直于 \( A \) 的每一列之时；这一正交性条件给出同一个方程组。<sup>[10](https://arxiv.org/abs/2412.19960)</sup> 当 \( A \) 列满秩时，\( A^{\top}A \) 正定，解唯一；此时可通过乔列斯基分解 \( A^{\top}A = LL^{\top} \) 求得。<sup>[2](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)</sup>

正规方程易于推导，但在数值上颇为敏感。构造 \( A^{\top}A \) 会使条件数平方，因此计算解的相对误差与 \( [\mathrm{cond}(A)]^2 \) 成正比；若 \( \mathrm{cond}(A) \approx 1/\sqrt{\mathrm{machine\ epsilon}} \) 或更糟，乔列斯基分解预计会失效。<sup>[2](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)</sup>

## 求解方法

**正交分解。** 豪斯霍尔德QR分解用一个正交矩阵将问题化为三角形形式，既保持最小二乘解不变，又避免条件数带来的惩罚。其代价约为 \( mn^2 - n^3/3 \) 次乘法；当 \( m \gg n \) 时约为正规方程工作量的两倍，而当 \( m \approx n \) 时两种方法代价大致相同。所得解的相对误差与 \( \mathrm{cond}(A) + \|r\|_2[\mathrm{cond}(A)]^2 \) 成正比，这与问题本身的固有敏感性相符。<sup>[2](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)</sup>

**奇异值分解。** SVD能精确处理秩亏矩阵，通过奇异值揭示数值秩结构，并在秩亏时给出最小范数最小二乘解。其代价与 \( mn^2 + n^3 \) 成正比，比例常数视算法而定，在4到10之间，这使它成为三种直接途径中最稳健却也最昂贵的一种。<sup>[2](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)</sup><sup> • </sup><sup>[11](https://sabioresearch.com/books/linear-algebra/en/ch17-least-squares.html)</sup> 在LAPACK中，驱动例程xGELS通过QR或LQ分解求解满秩问题，而xGELSS与xGELSD则使用SVD，后者采用分治算法，用于秩亏情形。<sup>[12](https://www.netlib.org/lapack/lug/node27.html)</sup>

**稀疏问题的迭代方法。** 对于大型稀疏方程组，佩奇（Paige）与桑德斯（Saunders）于1982年提出的LSQR迭代逼近解，也能求解阻尼（正则化）最小二乘；其收敛性强烈依赖于问题行与列的缩放。<sup>[13](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lsqr.html)</sup>

**重新评估正规方程。** 一项2025年的基准研究主张，在 \( n \ge p \) 的常见表格型情形下，数据为稠密双精度且不存在完全多重共线性时，直接通过LU或乔列斯基分解求解无正则化的正规方程在数值上是安全的，且比通常推荐的SVD或QR方法快得多——这与五十年来教科书上的警告相悖。<sup>[14](https://papers.ssrn.com/sol3/Delivery.cfm/5811842.pdf?abstractid=5811842&mirid=1)</sup> 随机预处理提供了另一条途径：借助有效的预条件子，即便对于高度病态的矩阵，由预处理正规方程得到的解也几乎与基于QR的求解器得到的解一样精确。<sup>[15](https://arxiv.org/abs/2507.18466)</sup>

## 统计应用与局限

线性最小二乘回归可拟合任何形如 \( f(\vec{x};\vec{\beta}) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots \) 的函数，其中每个解释变量都乘以一个未知参数。NIST称其为使用最广泛的建模方法，能高效利用数据，使相对较小的数据集也能得出良好结果，且其成熟的理论支持为预测、校准与优化提供易于解释的统计区间。它也是其他方法的基础，包括非线性最小二乘、加权最小二乘和LOESS。<sup>[5](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm?trk=article-ssr-frontend-pulse_little-text-block)</sup>

其主要缺点在于线性模型在长区间上能呈现的形状有限、外推可能不佳，以及对离群值敏感：一两个异常数据点就可能严重扭曲最小二乘分析，因此针对离群值的模型验证至关重要。<sup>[5](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm?trk=article-ssr-frontend-pulse_little-text-block)</sup> 普通最小二乘假定矩阵 \( A \) 已知且精确，只有右端项带有随机误差；当包括 \( A \) 在内的所有数据都带有误差时，总体最小二乘更为合适——它最小化正交距离而非垂直距离，并由 \( [A, b] \) 的SVD计算得出。<sup>[2](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)</sup>

最小二乘软件的测试仍是一个现实关切。NIST的统计参考数据集项目提供了带有认证值的线性最小二乘数据集，认证值给出16位有效数字，涵盖参数估计、其标准差、残差标准差、R平方以及方差分析表；多重共线性的高难度数据集包括20世纪70年代初开发的朗利（Longley）数据和万普勒（Wampler）数据集，而人们已遇到过某些代码在其中一些数据集上产生负R平方和错误F统计量的情况。<sup>[16](https://www.itl.nist.gov/div898/strd/lls/lls_info.shtml)</sup>

## References

1. [NIST/SEMATECH e-Handbook, section 4.4.3.1, Least Squares](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm?pageid=293&pg=page&s=1406)
2. [Michael T. Heath, Scientific Computing: An Introductory Survey, Chapter 3, Linear Least Squares](https://heath.cs.illinois.edu/scicomp/notes/chap03_8up.pdf)
3. [A Source Book in Mathematics: Legendre on Least Squares, Wikisource](https://en.wikisource.org/wiki/A_Source_Book_in_Mathematics/Legendre_on_Least_Squares)
4. [Lars Eldén and others, The calculation of linear least squares problems, Acta Numerica](https://www.cambridge.org/core/journals/acta-numerica/article/abs/calculation-of-linear-least-squares-problems/BA6F7F3457DA9172A313452C85E4702E)
5. [NIST/SEMATECH e-Handbook, section 4.1.4.1, Linear Least Squares Regression](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm?trk=article-ssr-frontend-pulse_little-text-block)
6. [Adrien Marie Legendre, Nouvelles méthodes pour la détermination des orbites des comètes, F. Didot, 1805, Google Books](https://books.google.fr/books?hl=fr&id=PRcOAAAAQAAJ)
7. [The method of least squares, Stemma](https://stemmascience.org/en/node/least_squares/)
8. [Stephen M. Stigler, An attack on Gauss published by Legendre in 1820, Journal for the History of Astronomy](https://www.sciencedirect.com/science/article/pii/0315086077900325)
9. [Method of Least Squares, Royal Holloway, University of London](https://www.gtfp.cs.rhul.ac.uk/pulskamp/Least_Squares/index.html)
10. [Numerical Linear Algebra: Least Squares, QR and SVD, arXiv:2412.19960](https://arxiv.org/abs/2412.19960)
11. [Projections, Pseudoinverse, and Least Squares, Sabio Research](https://sabioresearch.com/books/linear-algebra/en/ch17-least-squares.html)
12. [LAPACK Users' Guide, Linear Least Squares (LLS) Problems](https://www.netlib.org/lapack/lug/node27.html)
13. [scipy.sparse.linalg.lsqr, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lsqr.html)
14. [Albert Dorador, The Normal Equations Are Normally Faster: Benchmarking Ordinary Least Squares Solvers for n ≥ p, SSRN](https://papers.ssrn.com/sol3/Delivery.cfm/5811842.pdf?abstractid=5811842&mirid=1)
15. [Solution of Least Squares Problems with Randomized Preconditioned Normal Equations, arXiv:2507.18466](https://arxiv.org/abs/2507.18466)
16. [NIST Statistical Reference Datasets, Linear Least Squares Background Information](https://www.itl.nist.gov/div898/strd/lls/lls_info.shtml)

---
*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/linear-least-squares

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