2.6概率
P46
安装d2l
https://blog.youkuaiyun.com/qq_41990294/article/details/126735441?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168923092416800180686795%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=168923092416800180686795&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogtop_click~default-2-126735441-null-null.268v1control&utm_term=%E5%AE%89%E8%A3%85d2l&spm=1018.2226.3001.4450
亲测好用!
3.1线性神经网络
P62
>>> import math
>>> import time
>>> import numpy as np
>>> import torch
>>> from d2l import torch as d2l
>>> import random
>>> def synthetic_data(w, b, num_examples):
... """生成 y = Xw + b + 噪声。"""
... X = torch.normal(0, 1, (num_examples, len(w)))
... y = torch.matmul(X, w) + b
... y += torch.normal(0, 0.01, y.shape)
... return X, y.reshape((-1, 1))
>>> true_w = torch.tensor([2, -3.4])
>>> true_b = 4.2
>>> features, labels = synthetic_data(true_w, true_b, 1000)
>>>