Hello, I want to know why the loss of this linear regression has not been reduced.

import torch as t
from matplotlib import pyplot as plt
from IPython import display

def number(batch_size):
x = t.rand(batch_size , 1)*5
y = 2 * x + 3 + t.randn(batch_size , 1)
return x , y
x , y = number(500)

model = t.nn.Sequential(
t.nn.Linear(1, 1)
)

loss_fn = t.nn.MSELoss()
optimizer = t.optim.Adam(model.parameters() , lr = 0.01)

for i in range(5000):
y_pred = model(x)
loss = loss_fn(y_pred , y)
optimizer.zero_grad()
loss.backward()
optimizer.step()
print(loss)

The loss is reduced from ~104 to ~1.01 in my environment.
Note that you can post code snippets by wrapping them into three backticks ```, which makes debugging and helping easier. :wink: