Hi everyone,
I’m new to Pytorch and wanted to use it for simple Linear Regression for sensor data. The features are the longitude and latitude and the labels are pressure (values from 0-200) I found that when changing the scale of the data to values between 0 & 1, the loss is decreasing. Is there a reason for that? The model is just linear regression, nothing else.
#Model
features=train_X.shape[1]
input_size=features
output_size=1
model=nn.Linear(input_size,output_size)
device = torch.device(“cuda:0” if torch.cuda.is_available() else “cpu”)
#send to GPU if available
model.to(device)
train_X=train_X.to(device)
train_Y=train_Y.to(device)
validate_X=validate_X.to(device)
validate_Y=validate_Y.to(device)
#loss & optimizer
learning_rate=0.01
epochs=100
criterion=nn.MSELoss()
optimizer=torch.optim.SGD(model.parameters(),lr=learning_rate)
#training
for epoch in range(epochs):
#forward
y_predicted=model(train_X)
loss=criterion(y_predicted,train_Y)
#backward
loss.backward()
#updates
optimizer.step()
#zero gradients
optimizer.zero_grad()
#print info
if(epoch+1) % 10 ==0:
print(f’epoch: {epoch+1}, loss={loss.item():.4f}’)