Unitary linear regression
this is net
class LinearRegression(nn.Module):
    def __init__(self):
        super(LinearRegression, self).__init__()
        self.linear = nn.Linear(1, 1)

    def forward(self, x):
        x = self.linear(x)
        return x

This is the entire code
import torch as t
from matplotlib import pyplot as plt
from IPython import display
import torch.nn as nn
from torch.autograd import Variable
t.manual_seed(1000)
def get_fake_data(batch_size = 800):
    """y=2*x+3,生成x，并加入噪声"""
    x = t.rand(batch_size, 1) * 20
    y = 2 * x + 3 + t.randn(batch_size, 1)
    return x, y


x, y = get_fake_data()
plt.scatter(x.numpy(), y.numpy())
#  随机初始化参数
w = t.randn(1, 1)
b = t.zeros(1, 1)
lr = 0.001  # learning rate


class LinearRegression(nn.Module):
    def __init__(self):
        super(LinearRegression, self).__init__()
        self.linear = nn.Linear(1, 1)

    def forward(self, x):
        x = self.linear(x)
        return x


print(x[1],y[1])

Thank you for your help