プリンキピア

第3章回帰のための線形ニューラルネットワーク

3.5.2. Defining the Loss Function3.5.2 損失関数の定義

The MSELoss class computes the mean squared error (without the 1/2 factor in (3.1.5)). By default, MSELoss returns the average loss over examples. It is faster (and easier to use) than implementing our own.
英語のヒント
MSELossクラスは平均二乗誤差を計算する((3.1.5)の1/2の係数は付かない)。既定では、MSELossは事例にわたる平均損失を返す。自分で実装するより速く(そして使いやすい)。
@d2l.add_to_class(LinearRegression)  #@save
def loss(self, y_hat, y):
    fn = nn.MSELoss()
    return fn(y_hat, y)