回帰のためのMSEとMAE
正解値からの距離にペナルティを課します
「回帰のためのMSEとMAE」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Regression Needs Its Own Loss
When your model predicts a number like a price or temperature, you need a regression loss that measures how far each guess lands from the true value. 📏
Meet Mean Squared Error
MSE squares every prediction error, then averages them. Squaring keeps all errors positive and punishes big misses much harder than small ones.
MSE in One Line
PyTorch gives you nn.MSELoss, so you never write the formula by hand. You pass predictions and targets and get a single scalar back.
import torch.nn as nn
loss_fn = nn.MSELoss()
loss = loss_fn(pred, target)Why Squaring Matters
Because MSE squares errors, an error of 4 counts 16x more than an error of 1. That makes MSE very sensitive to large mistakes and outliers.
Meet Mean Absolute Error
MAE averages the absolute size of each error instead of squaring it. Every mistake counts in proportion to how big it actually is.
MAE in PyTorch
Use nn.L1Loss for MAE. The name comes from the L1 norm, which simply sums absolute differences before averaging.
import torch.nn as nn
loss_fn = nn.L1Loss()
loss = loss_fn(pred, target)MAE Shrugs Off Outliers
Since MAE never squares anything, one wild outlier does not blow up the loss. That makes it the calmer, more robust choice for messy data.
MSE vs MAE: The Tradeoff
Pick MSE when big errors are truly worse and your data is clean. Pick MAE when outliers are noise you do not want to chase.
What the Number Means
A regression loss is in your target's units (squared for MSE). Lower is better, but compare it across models, not as an absolute score.
Huber: The Best of Both
Want robustness and smooth gradients? Huber loss acts like MSE for small errors and like MAE for large ones, blending both behaviors.
import torch.nn as nn
loss_fn = nn.SmoothL1Loss()
loss = loss_fn(pred, target)Match Loss to Output Shape
For regression your final layer outputs raw numbers with no activation. The loss compares those values straight to the targets.
Quick Check
One outlier is dominating your training. Which loss is most robust to it?
Recap: Distance, Measured
You now read regression error two ways: MSE punishes big misses by squaring, while MAE stays steady against outliers. Match the loss to your data and you are set. 🎯
よくある質問
「回帰のためのMSEとMAE」レッスンは無料ですか?
はい。「回帰のためのMSEとMAE」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。
「回帰のためのMSEとMAE」で何を学びますか?
正解値からの距離にペナルティを課します ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Deep Learning Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「回帰のためのMSEとMAE」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDeep Learning Academyレッスンでコードを書いて実行できますか?
はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 回帰のためのMSEとMAE
- ロジット付きバイナリクロスエントロピー
- マルチクラス分類のクロスエントロピー
- 不均衡データのためのクラス重み