Lab · Overfitting过拟合实验 · 过拟合
Will this year’s curve work next year?今年的曲线明年还管用吗?
A housing analyst has this year’s trust score for 24 districts, and one column: the share of households in public rental housing. The analyst fits a curve so next year’s outreach budget can go to districts the curve marks as low-trust. A curve that sits on all 24 dots can miss the next 400 districts drawn the same way. That too-close fit is overfitting.一位房屋分析员有今年 24 个区的信任分数,和一列数字:公屋住户的占比。分析员拟合一条曲线,好把明年的宣传预算投到曲线标成低信任的区。一条贴住全部 24 个点的曲线,可以错过按同样方式抽出的下一批 400 个区。贴得太紧,就是过拟合。
Why this matters.为何重要。 A curve that sits closer to this year’s 24 districts can miss next year’s. The bend is how much the curve is allowed to follow single districts. The two numbers under the chart are this year’s miss and next year’s miss.一条更贴近今年 24 个区的曲线,可能错过明年的。弯曲是曲线被允许跟着单个区走多少。图下的两个数是今年的偏差和明年的偏差。
Try this试一试 Move the bend from 1 to 3, then to 12. Watch the solid curve and compare this year’s miss with next year’s. Draw a new set of districts before you treat one curve as the budget.把弯曲从 1 调到 3,再到 12。看实线,并比较今年的偏差和明年的偏差。把一条曲线当成预算之前,先再抽一批区。
Read the chart读这张图
If you misread this读错了会怎样
If the housing analyst sends next year’s outreach budget to districts where this curve is lowest, the money can miss the districts that are actually low-trust. The small error is on this year’s 24 dots. A curve allowed to bend more can sit farther from next year’s districts.如果房屋分析员把明年的宣传预算投到这条曲线标成最低的区,钱可能错过真正低信任的区。那个小误差是今年这 24 个点上的。允许弯得更多的曲线,可以离明年的区更远。
Enough, and not enough够用,以及不够
Enough to see this year’s miss on 24 districts and next year’s miss move apart as the curve is allowed to bend more.够用来看见:曲线被允许弯得更多时,今年 24 个区上的偏差和明年的偏差会分开。
Not enough for the budget memo. It still needs a later year of districts that was not watched while the bend was chosen, and a reason a polynomial is the right shape for trust.不够写预算说明。说明仍需要在挑选弯曲程度时没有盯着的下一年的区,以及多项式是信任分数合适形状的理由。
Equations, assumptions, and limits方程、假设与限度
X is uniform on [−1, 1]; Y = sin(πX) + σe, with independent standard normal noise e. Polynomial regression uses least squares with an intercept and degree d. A Chebyshev basis with re-orthogonalised QR improves numerical stability without changing the polynomial model; there is no regularisation.X 在 [−1, 1] 上均匀;Y = sin(πX) + σe,e 为独立的标准正态噪声。多项式回归用最小二乘,含截距,次数为 d。切比雪夫基配合再正交的 QR 提高数值稳定性,但不改变多项式模型;没有正则化。
Mean squared error (MSE) averages squared prediction errors against noisy outcomes. Greater model flexibility cannot increase the minimum training error in exact arithmetic; validation error need not improve. One sample does not guarantee a U-shaped curve.均方误差(MSE)是对带噪声结果的预测误差平方的平均。在精确算术里,模型更灵活不能提高最小训练误差;验证误差不必改善。一次样本不能保证 U 形曲线。
Because you can tune the degree while watching validation performance, this is a validation set, not a final untouched test set. Real work also needs an appropriate split (for example, by time or social group) and a final independent evaluation. The experiment does not represent all modern machine-learning models.因为你可以一边看验证表现一边调次数,这是验证集,不是一份最终没碰过的测试集。真实工作还需要合适的划分(例如按时间或社会群体),以及一次独立的最终评估。本实验不代表所有现代机器学习模型。
Common pitfall.常见陷阱。 Introductory texts describe a bias–variance tradeoff. A stiff model can miss the curve in a similar way on every sample. A very flexible model can change shape from sample to sample. This page does not estimate those two pieces. It shows training error and validation error for one degree at a time. A pitfall is to treat the validation error you watched while choosing the degree as an untouched test error. Another is to expect a neat U-shape in every sample. A third is to assume a wiggly curve must be regularized. This fit is ordinary least squares. Flexibility here is the degree, not a penalty.入门教材描述偏差—方差权衡。僵硬的模型可能在每个样本上以相似的方式错过曲线。非常灵活的模型可能在不同样本上改变形状。本页不估计那两部分。它一次显示一个次数的训练误差和验证误差。一个陷阱是把你看着验证误差选次数时的那个误差当成没碰过的测试误差。另一个是期望每次样本都有整齐的 U 形。第三个是以为弯曲的曲线一定被正则化了。这个拟合是普通最小二乘。这里的灵活性是次数,不是惩罚。