Back to tree

📏 损失函数:量“差多远”的尺子📏 Loss Function: the Ruler of Wrongness

上一片里,信号一路向前,出口给出了答案。可这个答案离目标差多远?机器人掏出一把尺子——损失函数(Loss Function),专门量“差多远”。 Last leaf, the signal flowed forward and the exit gave an answer. But how far is that answer from the target? Out comes a ruler — the loss function — built to measure exactly that.

第 1 步:一把量差距的尺子Step 1: A ruler that measures the gap

脱靶的箭与大尺子:损失 = 差多远
机器人射出一箭,箭落在靶心旁边。一把大尺子从落点量到靶心——差 3 环,损失就是 3。差得越远,数值越大。损失函数就是这把尺子:把“差多远”变成一个数。数字越小,答案越准。 The robot shoots an arrow; it lands beside the bullseye. A big ruler measures from the landing spot to the center — 3 rings off, so the loss is 3. The farther the miss, the bigger the number. The loss function is that ruler: it turns “how far off” into one number. Smaller number, better answer.

可“差多远”有好几种量法,为什么偏偏要两把尺子?But “how far off” can be measured in different ways — why keep two rulers?

第 2 步:两把尺子——碗和 VStep 2: Two rulers — the bowl and the V

两联对比:平方误差的碗 vs 绝对误差的 V
平方误差(MSE):先把差距平方再量。差 2 得 4,差 5 得 25——越远罚得越狠,曲线像陡峭的碗。绝对误差(MAE):直接量差距本身。差 2 得 2,差 5 得 5——远近一视同仁,曲线是 V 形。大错要重罚用碗,一视同仁用 V。 Squared error (MSE) squares the gap first: off by 2 gives 4, off by 5 gives 25 — far misses are punished harder, and the curve looks like a steep bowl. Absolute error (MAE) just takes the gap itself: off by 2 gives 2, off by 5 gives 5 — fair at any distance, and the curve is a V. Want big misses punished hard? Use the bowl. Want fairness at any distance? Use the V.

尺子量出的数字,在训练里到底有什么用?So what does that number actually do during training?

第 3 步:训练时盯着它变小Step 3: Watch it shrink while training

训练面板:下降的损失曲线与喝茶的小机器人
训练面板上那条一路向下的曲线,就是损失在变小:机器人每调一次参数,就再量一次差距。曲线不再降:学到头了。曲线忽上忽下:脚步(学习率)没调好。 That curve sliding downward on the training panel is the loss shrinking: every time the robot adjusts its settings, it measures the gap again. When the curve stops falling, learning has hit its limit. When it bounces up and down, the step size (learning rate) needs tuning.

🎮 把误差压下去(30 秒)🎮 Push the loss down (30 seconds)

道理讲完了。靶心随机出现——拖动滑块让预测值对准它,把损失压进绿色区。连中 3 次就算通关!Theory done. A bullseye appears at random — drag the slider so your prediction lands on it and push the loss into the green zone. Three hits in a row and you win!

一句话记住它:损失函数 = 一把量“答案离目标差多远”的尺子;训练,就是想办法把这个数压小。 Remember it in one line: a loss function is a ruler that measures how far your answer is from the target — and training is the game of making that number small.
靶心与箭头:差得越远,损失越大Bullseye & arrow: the farther the miss, the bigger the loss 平方误差是陡峭的碗(大错重罚),绝对误差是 V 形(远近一视同仁)Squared error is a steep bowl (hard on big misses); absolute error is a V (fair at any distance) 训练曲线一路向下 = 越学越准;不降 = 学到头;忽上忽下 = 步伐问题A falling training curve = learning; flat = done; bouncing = a step-size problem

← 浏览全部 302 个知识点← Browse all 302 topics

内容参考 OpenStax 等公开教材,多来源核对 · AI 生成、人工审核 · 发现错误欢迎指正,帮这片叶子长得更好。 Based on OpenStax and other open textbooks, cross-checked across sources · AI-generated, human-reviewed · Spotted a mistake? Tell us — help this leaf grow.