第3章回帰のための線形ニューラルネットワーク
3.7.2. High-Dimensional Linear Regression3.7.2 高次元の線形回帰
We can illustrate the benefits of weight decay through a simple synthetic example.
英語のヒント
簡単な合成の例で、重み減衰の利点を示せる。
First, we generate some data as before:
英語のヒント
まず、前と同じようにデータを生成する。
(3.7.4)
In this synthetic dataset, our label is given by an underlying linear function of our inputs, corrupted by Gaussian noise with zero mean and standard deviation 0.01. For illustrative purposes, we can make the effects of overfitting pronounced, by increasing the dimensionality of our problem to and working with a small training set with only 20 examples.
英語のヒント
この合成データセットでは、ラベルは入力の根底にある線形関数で与えられ、平均0、標準偏差0.01のガウスノイズで乱されている。説明のために、問題の次元数をに増やし、事例がたった20個の小さな訓練集合を使うことで、過学習の効果を際立たせることができる。
class Data(d2l.DataModule):
def __init__(self, num_train, num_val, num_inputs, batch_size):
self.save_hyperparameters()
n = num_train + num_val
self.X = torch.randn(n, num_inputs)
noise = torch.randn(n, 1) * 0.01
w, b = torch.ones((num_inputs, 1)) * 0.01, 0.05
self.y = torch.matmul(self.X, w) + b + noise
def get_dataloader(self, train):
i = slice(0, self.num_train) if train else slice(self.num_train, None)
return self.get_tensorloader([self.X, self.y], train, i)