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)