在训练模型的过程中,我们需要不断的读取小批量的数据样本。Pytorch提供了data
包来读取数据。接下来我将人工生成一些数据,然后使用data
包来处理数据。
import torch
import numpy as np
'''
The features number is 3, and the number of examples is 1000.
'''
true_w = [2, 3, 5.3]
true_b = 9.7
features = torch.tensor(np.random.normal(0, 1, (1000, 3)), dtype=torch.float)
labels = true_w