深度学习 #01
# 线性回归的从零开始实现 In[6]: get_ipython().run_line_magic('matplotlib', 'inline') import torch from IPython import display from matplotlib import pyplot as plt import numpy as np import random ## 生成数据集 In[7]: num_inputs = 2 num_examples = 1000 true_w = [2, -3.4] true_b = 4.2 features = torch.randn(num_examples, num_inputs, dtype=torch.float32) labels = true_w[0] * features[:, 0] + true_w[1] * features[:, 1] + true_b labels += torch.tensor(np.random.normal(0, 0.01, size=labels.size()), dtype=torch.float32) In[8]: print(features[0], labels[0]) In[9]: def use_svg_display(): # 用矢量图显示 display.set