プリンキピア

第5章多層パーセプトロン

5.7.5. Error Measure5.7.5 誤差の尺度

To get started we will train a linear model with squared loss. Not surprisingly, our linear model will not lead to a competition-winning submission but it does provide a sanity check to see whether there is meaningful information in the data. If we cannot do better than random guessing here, then there might be a good chance that we have a data processing bug. And if things work, the linear model will serve as a baseline giving us some intuition about how close the simple model gets to the best reported models, giving us a sense of how much gain we should expect from fancier models.
英語のヒント
手始めに、二乗損失で線形モデルを訓練する。当然ながら、線形モデルでコンペティションに勝てる提出にはならないが、データに意味のある情報があるかどうかを見る正常性の確認にはなる。ここで当てずっぽうよりうまくやれないなら、データ処理にバグがある見込みが大きいかもしれない。そしてうまくいけば、線形モデルはベースラインとして働き、単純なモデルが報告されている最良のモデルにどこまで迫れるかについての直観を与え、もっと凝ったモデルからどれだけの改善を期待すべきかの感覚をつかませてくれる。
With house prices, as with stock prices, we care about relative quantities more than absolute quantities. Thus we tend to care more about the relative error y−yˆy than about the absolute error y−yˆ. For instance, if our prediction is off by $100,000 when estimating the price of a house in rural Ohio, where the value of a typical house is $125,000, then we are probably doing a horrible job. On the other hand, if we err by this amount in Los Altos Hills, California, this might represent a stunningly accurate prediction (there, the median house price exceeds $4 million).
英語のヒント
住宅価格では、株価と同じく、絶対的な量より相対的な量を気にかける。そのため、絶対誤差y−yˆより相対誤差y−yˆyのほうを気にかける傾向がある。たとえば、典型的な住宅の価値が12万5千ドルであるオハイオ州の田舎で住宅の価格を推定するときに、予測が10万ドルずれていたら、おそらくひどい仕事をしている。他方、カリフォルニア州のロスアルトスヒルズでこれだけ誤ったなら、それは驚くほど正確な予測かもしれない(そこでは住宅価格の中央値は400万ドルを超える)。
One way to address this problem is to measure the discrepancy in the logarithm of the price estimates. In fact, this is also the official error measure used by the competition to evaluate the quality of submissions. After all, a small value δ for |log⁡y−log⁡yˆ|≤δ translates into e−δ≤yˆy≤eδ. This leads to the following root-mean-squared-error between the logarithm of the predicted price and the logarithm of the label price:
英語のヒント
この問題に対処する一つの方法は、価格の推定値の対数で食い違いを測ることである。実際、これはコンペティションが提出物の質を評価するのに使う公式の誤差の尺度でもある。何しろ、|log⁡y−log⁡yˆ|≤δとなる小さな値δは、e−δ≤yˆy≤eδに言い換えられる。これにより、予測価格の対数とラベルの価格の対数のあいだの、次の二乗平均平方根誤差が導かれる。
1n∑i=1n(log⁡yi−log⁡yˆi)2.(5.7.2)
@d2l.add_to_class(KaggleHouse)
def get_dataloader(self, train):
    label = 'SalePrice'
    data = self.train if train else self.val
    if label not in data: return
    get_tensor = lambda x: torch.tensor(x.values.astype(float),
                                      dtype=torch.float32)
    # Logarithm of prices
    tensors = (get_tensor(data.drop(columns=[label])),  # X
               torch.log(get_tensor(data[label])).reshape((-1, 1)))  # Y
    return self.get_tensorloader(tensors, train)