I am new study ML,my idea is use x_data( Height、 weight)to predict y_data(life), y=ax(1)+bx(2)+c, then x(1) is Height or Weight should not change the regression result, but through the code the location affect regression results. my question 1、if not use SGD optimizer, the linear regression is bad, loss is very big, and the regression result is same, a=-0.4912,b=0.2071, but I think a、b should change the number. 2、if use SGD optimizer,the result is not the same and every time there are different values, so i am confused.
import torch
import torch.nn as nn
from torch.autograd import Variable
import numpy as np
torch.manual_seed(777)
x_data = [[1.3, 2.7], [2.4, 3.3],[4.7, 5.2], [5.6, 6.1], [6.9, 7.9]]
#x_data = [[2.7, 1.3], [3.3, 2.4],[5.2, 4.7], [6.1, 5.6], [7.9, 6.9]] #Column to column change
y_data = [[6.], [9.], [15.], [18.], [21.]]
x=Variable(torch.Tensor(x_data).view(5,-1))
y=Variable(torch.Tensor(y_data)).view(5,-1) ;print(x.size(),y.size())
#our hypothesis xw+b
model=nn.Linear(2,1,bias=True)
print(model)
#cost Criterion #minimize
criterion=nn.MSELoss()
#optimizer=torch.optim.SGD(model.parameters(),lr=1e-5)
#train the model
for step in range(200001):
#optimizer.zero_grad()
#our hypothesis
hypothesis=model(x)
cost=criterion(hypothesis,y)
cost.backward()
#optimizer.step()
if step %10==0:
print(step,'cost: ',cost.data.numpy(),'\nprediction:\n',hypothesis.data.numpy())
print('-------------------------')
print(model.weight.data.numpy(),model.bias.data.numpy())