Learn Before
Code
SyntheticRegressionData Class
The SyntheticRegressionData class encapsulates the procedural generation of synthetic datasets for linear regression models. Inheriting from a base DataModule (such as d2l.DataModule), its init constructor takes the true parameters w and b, alongside hyperparameters like noise (defaulting to ), num_train, num_val, and batch_size. After invoking save_hyperparameters(), it constructs the feature matrix from a normal distribution and computes the label vector using the formula . This structure standardizes the dataset preparation for training and validation.
0
1
Updated 2026-05-02
Tags
D2L
Dive into Deep Learning @ D2L