Home首页 · Machine Learning机器学习 · Regularization正则化

Lab · Regularization正则化实验 · 正则化

What stays in the note when slopes are pulled toward zero?斜率被往零拉时,说明里还留下什么?

Same 24 districts and the same trust score. The curve is now fixed at degree 10, so the analyst no longer chooses the degree. They choose a penalty instead, and then decide which housing features to name in a one-page note. Ridge shrinks every slope. Lasso can set some slopes to exactly zero. A bar that disappears was dropped by this penalty on these 24 districts.还是这 24 个区,还是这份信任分数。曲线现在固定为 10 次,分析员不再选次数,而选一个惩罚,然后决定一页说明里要点哪些房屋特征。岭回归缩小每一个斜率。套索可以把一些斜率恰好设成零。消失的一条,是这个惩罚在这 24 个区上丢掉的。

Why this matters.为何重要。 A curve that follows this year’s noisy trust scores can miss next year. Pulling the slopes toward zero makes the curve move less on a new set of districts. The price is a larger miss this year. The page shows those two misses and the slopes.一条跟上今年吵闹的信任分数的曲线,可能错过明年。把斜率往零拉,曲线在新的一批区上少动一些。代价是今年的偏差变大。这一页给出这两个偏差,和那些斜率。

Try this试一试 Leave the pull at zero, then raise it. Switch from shorten-only to deletions and watch bars disappear. Compare this year’s miss with next year’s before you say the pull helped.先把拉力留在零,再提高它。从“只缩短”换到“可删除”,看条消失。在说拉力有帮助之前,比较今年的偏差和明年的偏差。

24 training / 200 validation observations · degree fixed at 10 · same sample while you move λ.24 个训练 / 200 个验证观测 · 次数固定为 10 · 移动 λ 时用同一样本。

Each dot is one district this year. The solid line is the curve after the pull. The dashed line is the trust pattern. Each bar is one slope. A missing bar was deleted from the note.每个点是今年的一个区。实线是被拉动之后的曲线。虚线是信任的形态。每一条是一个斜率。缺掉的条是从说明里删掉的。

Read the chart读这张图

If you misread this读错了会怎样

If the analyst drops public-rental share from the one-page note because its bar vanished, the note can omit a feature that marked low-trust districts. The zero is this penalty on these 24 districts. Change the penalty, or score that share as a percent instead of a fraction, and the bar can return.如果分析员因为条消失了,就从一页说明里删掉公屋占比,说明可能会漏掉一个标出低信任区的特征。这个零是这个惩罚在这 24 个区上的结果。改变惩罚,或把这个占比从小数改成百分数,条可以回来。

Enough, and not enough够用,以及不够

Enough to see ridge shorten every slope, lasso delete some, and both this year’s miss and next year’s miss move.够用来看见:岭回归缩短每个斜率,套索删掉一些,今年的偏差和明年的偏差都会动。

Not enough for the one-page note. It still has to choose the penalty without looking at a final untouched year of districts, and check the shortened curve still falls where trust is low.不够写那一页说明。说明仍要在不看最后一年没碰过的区的情况下选定惩罚,并检查缩短后的曲线仍然落在信任低的地方。

Seed 42
Equations, assumptions, and limits方程、假设与限度

Current equation当前方程

X is uniform on [−1, 1] and Y = sin(πX) + 0.3e. The fit is a degree-10 polynomial in a Chebyshev basis. Columns other than the intercept are centered and scaled on the training sample, so λ has a meaning only for that scaling. Ridge adds λ times the sum of squared slopes to the residual sum of squares. Lasso adds λ times the sum of absolute slopes. The intercept is free in both.X 在 [−1, 1] 上均匀,Y = sin(πX) + 0.3e。拟合是切比雪夫基上的 10 次多项式。除截距外的列在训练样本上中心化并缩放,所以 λ 只对这种缩放有意义。岭回归把 λ 乘斜率平方和,加到残差平方和上。套索把 λ 乘斜率绝对值和加进去。两种里截距都自由。

Shrinking slopes can raise training error and lower validation error, until the penalty is so large that the curve misses the sine wave and both errors rise. Lasso’s zeros are a feature of the absolute penalty. Ridge rarely produces an exact zero. One sample does not guarantee a U-shaped validation curve.缩小斜率可以提高训练误差、降低验证误差,直到惩罚大到曲线错过正弦波,两种误差一起上升。套索的零来自绝对惩罚。岭回归很少产生恰好的零。一次样本不能保证验证曲线呈 U 形。

Common pitfall.常见陷阱。 The λ that looks best while you watch the validation error is a tuning choice. That number is not an untouched test error. Another pitfall is to read a lasso zero as “this term is irrelevant in the world.” It was irrelevant to this penalized fit on this sample. A third is to treat the numeric λ as portable. Change the scaling of X and the same λ means a different penalty.你看着验证误差时显得最好的 λ 是调参选择。那个数不是没碰过的测试误差。另一个陷阱是把套索的零读成“这一项在世界上无关”。它只是在这一次带惩罚的拟合里无关。第三个陷阱是把 λ 的数值当成可搬家的。改变 X 的缩放,同一个 λ 就是不同的惩罚。

Books behind this lab are named on the本实验背后的书按主题列在About关于.