故事 · 一颗小行星与两位数学家 Story · One Dwarf Planet and Two Mathematicians
1801 年,天文学家发现了矮行星谷神星,但还没算清它的轨道,它就转到太阳背后失踪了。只剩下几十个带误差的观测点。 年仅 24 岁的 高斯(Gauss) 用一种新方法从乱点里反推出轨道,几个月后人们果然在他预言的位置重新找到了谷神星 —— 一举成名。 几乎同时,法国的 勒让德(Legendre) 也公开发表了同样的方法,两人为发明权争论不休。这个方法就是最小二乘: 让残差(观测值减预测值)的平方和最小。高斯还证明了:当误差服从正态分布时,最小二乘给出的就是最优估计 —— 这把上一页的正态分布和回归分析牢牢焊在了一起。今天从趋势线、标定曲线到机器学习,背后都是它。 In 1801, astronomers discovered the dwarf planet Ceres, but before they could pin down its orbit it vanished behind the Sun — leaving only a few dozen noisy observations. Just 24 years old, Carl Friedrich Gauss invented a new method to reconstruct the orbit from that messy cloud of points, and months later Ceres was found exactly where he predicted — overnight fame. Almost at the same time, in France, Adrien-Marie Legendre published the same method, and the two argued for years over priority. That method was least squares: minimize the sum of squared residuals (observed minus predicted). Gauss went further and proved that, when errors are normally distributed, least squares yields the maximum-likelihood (and hence optimal) estimate — welding the previous page's normal distribution onto regression analysis. From trend lines and calibration curves to modern machine learning, the same engine is still humming underneath.

1 拖动任意一点,看线如何重新"站位" Drag Any Point and Watch the Line Re-anchor Itself

拟合良好

2 为什么平方?大偏差被狠狠放大 Why Square? Because Big Deviations Get Hammered

平方(橙)相比绝对值(蓝)对大残差的惩罚陡增:偏差翻倍,代价变 4 倍。这让拟合线对离群点更敏感,也让数学解唯一且可求导。 The squared loss (orange) penalises large residuals far more sharply than the absolute loss (blue): double the deviation, quadruple the cost. That makes the line more sensitive to outliers — and gives it a unique, differentiable solution.

3 现实里的最小二乘 Least Squares in the Real World

回归基础:线性回归、多元回归的系数都靠最小二乘求出,是六西格玛分析阶段的核心工具。 The basis of regression: the coefficients in linear and multiple regression all come from least squares — a core tool in the Analyze phase of Six Sigma.
曲线拟合:标定曲线、趋势预测、量具线性度评估,都是把点拟合成一条最优线。 Curve fitting: calibration curves, trend forecasting, and gauge-linearity studies all boil down to fitting an optimal line through data points.
高斯与勒让德:从天体轨道反推到现代数据科学,两百年的方法谱系一脉相承。 Gauss & Legendre: from reconstructing celestial orbits to modern data science — two centuries of methodology share the same lineage.
残差最小化:让预测与实测的差异平方和最小,是几乎所有"拟合"任务的统一目标。 Residual minimization: minimizing the squared gap between prediction and observation is the unifying objective behind almost every fitting task.
一句话In One Line
最小二乘的精髓是把"哪条线最好"这个含糊的问题,变成一个能精确求解的最优化问题: 最小化 Σ(yᵢ − ŷᵢ)²。选平方而非绝对值,有三个理由:数学上可导、解唯一闭式(一组正规方程直接算出 a、b); 统计上,当误差正态时它就是最大似然估计(高斯亲自证明);工程上,它重罚大偏差,逼着线照顾整体。 它是回归分析的发动机,也是 R² 的来源 —— 你拖动散点时看到的 R²,正是"这条线解释了数据多少波动"。 代价是:对离群点极其敏感,一个异常点就能把线拽歪,所以用前一定要先看残差、查离群。 The essence of least squares is to turn the vague question "which line is best?" into a well-posed optimization problem: minimize Σ(yᵢ − ŷᵢ)². Why squared rather than absolute residuals? Three reasons. Mathematically, the loss is differentiable everywhere and has a unique closed-form solution — the normal equations spit out a and b directly. Statistically, under normal errors it coincides with the maximum-likelihood estimate (Gauss proved this himself) and is the Best Linear Unbiased Estimator (BLUE) by the Gauss–Markov theorem. Engineering-wise, squaring punishes large deviations, forcing the line to look after the bulk of the data. Least squares is the engine of regression and the source of R² — the value you see while dragging points tells you exactly how much variance the line explains. The price: extreme sensitivity to outliers. A single anomalous point can yank the line off course, so always inspect residuals and screen for outliers first.
常见误用Common Mistakes
有离群点不处理直接拟合平方放大离群影响,线会被拽歪;先查残差图,必要时用稳健回归。 Fitting straight through without dealing with outliers. Squared loss amplifies outlier influence and skews the line — inspect the residual plot first, and switch to robust regression when needed.
明明是曲线关系却硬拉直线残差呈系统弯曲就说明模型选错,应换多项式或变换后再拟合。 Forcing a straight line through an obviously curved relationship. Systematic curvature in the residuals signals the wrong model — switch to a polynomial term or transform the variables before refitting.
只看 R² 高就下因果结论R² 高只说明拟合好,相关不等于因果,还要看残差独立、方差齐性等假设。 Jumping to causal conclusions just because R² is high. High R² only means a tight fit. Correlation is not causation — also check independence of residuals, homoscedasticity, and the other OLS assumptions.

最小二乘法