import numpy as np
import torch
import matplotlib.pyplot as plt
数据准备
lr =0.02# 学习率# 创建训练集
torch.manual_seed(10)
x = torch.rand(20,1)*10
y =2*x +(5+torch.randn(20,1))# 构建线性回归参数
w = torch.randn([1],requires_grad=True)
b = torch.zeros([1],requires_grad=True)